Top 109 Scary Coding Interview Questions SOLVED with Answers

Written By John Sonmez

Programming Interview Questions

I know the feeling.

You’re before a big coding interview.

Yeah, you’ve got your education. You've become a software developer to the best of your ability. You’ve been putting in the coding reps.

But still.. Now, months or weeks before the big day..

Suddenly you’re starting to feel.. clueless. And to be honest – a bit scared.. or more than a bit!

[pullquote align=”normal”]What will those mean recruiters ask you? [/pullquote]

I’ve been through many coding interviews. More recently I’ve been on the other side, too – as an interviewer. I’ve even written a book all about programming interviews.

Why are coding interviews so hard?

Coding interviews ARE getting harder. Programmers are studying more to prepare. It’s getting more competitive. Interviewers adapt — by asking harder questions.

Also, it's just stressful to code under pressure. And the questions are often kept too short to be used as a useful screening tool. Instead they're tripping up even good coders.

But… if you’re smart and disciplined about preparing, you can still dominate that interview!

Study these questions inside-out.

Today I’ll spill the secret on the questions you face during a coding interview and how you tackle them successfully.

To ace your programming interview, you need to prepare with real programming interview questions. Practice on real problems and learn their patterns.

You’ll impress the interviewers with your informed, to-the-point answers, to where they’d be dumb not to hire you.

The world needs more great programmers (YOU!!) with well-paid jobs – so you can keep making the world a better place.

I sincerely wish that for you.

Good luck![blank_space height='0.1em']

[blank_space height='0.1em']

The 5 Types of Coding Interview Questions to Master

Take a moment.

Put on the shoes of who’s asking you the coding interview questions.

Recruiters want the full picture. They want to know about:

  1. your CODING KNOWLEDGE about basic programming concepts[blank_space height='1em']
  2. your CODING SKILLS, mostly related to data structures (arrays, strings, linked lists, binary trees..), concepts (bit manipulation, design patterns..) & algorithms[blank_space height='1em']
  3. your LOGICAL ABILITY in general. Sure,  intelligence is mostly inherited. But anyone can work to get everything out of their God-given level of intelligence: By practicing logic puzzles and refining their logic skills. [blank_space height='1em']
  4. your PROBLEM SOLVING PROCESS – it’s what makes you a good programmer vs. “just a coder”[blank_space height='1em']
  5. your PERSONALITY – and how well it fits their company’s culture & goals. These are the so-called “behavioral” interview questions.[blank_space height='0.5em']

The 5 categories:

  1. Coding knowledge
  2. Coding skills
  3. Logical ability
  4. Problem-solving
  5. Personality

Prepare yourself for questions in each of these areas. You’ll know what’s coming, and you’ll be able to give a smart answer. 

Show up to your programming interview (in-person or via video) well-prepared for these types of questions.

It’s your chance to outshine the other candidates.

Now, on to the 5 types of coding interview questions you need to master: [blank_space height='0.1em']

1. Basic programming interview questions 

Basic Programming Interview Questions

 

 

 

 

Early in the interview (and also throughout), interviewers are looking to test you on your programming fundamentals.

These are questions on general programming terms, concepts, and functions.

If you struggle on the basics, they’ll be able to quickly cross you off the list of job prospects. 

Coding Interview Questions for Freshers

If you're a fresher looking forward to your first coding interviews, start with the more basic questions in this article. Once you've mastered them, you can move on to more difficult questions, problems, and puzzles. Work on the “freshers” questions first, and you'll be ready for the most advanced stuff. But it all builds on the basics!

So make sure you understand these basic programming concepts:

The Top 13 General Coding, Design & Programming Fundamentals Questions

General Coding Questions

See how many of these questions you can answer in a row without slowing down.

1. What are the pros and cons of your chosen technology?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

If your favorite technology is Node.js, for example — you need to be able to answer this technical question thoroughly because it's going to show your depth of knowledge in this specific area.

And since you're more likely going to be interviewing for a Node.js job, pros and cons are often overlooked. And people just go, oh yeah, I use JavaScript. I use Node. They don't actually know the pros to use it, and they don't actually know the cons. And when they give answers, they might just say, “Oh yeah. Object oriented. Oh yeah. Great with memory.”

Don't be vague. Be to the point.

Find some pros and cons of your technology, and better yet, find pros and cons of anything on your resume.

[/thrive_toggles][/thrive_toggles_group]

2. What are variables? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″] Without variables, you don’t have a program. Variables are values that change within a program, based on the overall conditions and the “work” the program is doing. Variables are values stored or “declared” within the program and represent the working data set for the program. Variables = data sets + algorithms.[/thrive_toggles][/thrive_toggles_group]

3. What is inheritance? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Inheritance is one of the core concepts of object-oriented programming (OOP) languages. It is a mechanism where you can to derive a class from another class for a hierarchy of classes that share a set of attributes and methods.

You can use it to declare different kinds of exceptions, add custom logic to existing frameworks, and even map your domain model to a database.  (Source)

[/thrive_toggles][/thrive_toggles_group]

4. What is polymorphism? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Polymorphism allows new objects in programming to assume the properties of existing objects. The object providing the inherited characteristics is known as a “base class” or “superclass.”

This is a program’s ability to process an object differently, according to its type or class. Picture a car versus a tank. Polymorphism would be a system that provides a blueprint for the systems they have in common and works across both types of vehicle.

[/thrive_toggles][/thrive_toggles_group]

5. What are pointers? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Pointers contain memory addresses for other values. Manipulating pointers can save time versus manipulating the data the pointers refer to. This can be an efficient way to write programs that manipulate data.

Pointers are used often in C, but less so in Java.

[/thrive_toggles][/thrive_toggles_group]

6. Name four types of storage classes. [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Register, static, external, and automatic.

  1. Register: These are storage classes kept in the register of the central processing unit.
  2. Static: This is a storage class in which the variable does not change. It is declared at the beginning stages of the programming task.
  3. External: A storage class local to a piece of hardware, such as device drivers. These say to the compiler: “If I need this variable again, read it from the external device for the most current value.”
  4. Automatic: A storage class in which blocks or functions define local variables.

[/thrive_toggles][/thrive_toggles_group]

7. What is encapsulation? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

This is one of the most important concepts in object-oriented design. It involves bundling together a class with a set of instructions. In encapsulation, an object includes not just its data but also functions that can mutate that data. Encapsulation may be used to hide the nature of the data while still facilitating interaction.

[/thrive_toggles][/thrive_toggles_group]

8. Name seven data types. [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

  1. Floating point
  2. Integer
  3. String
  4. Float
  5. Real
  6. Character
  7. Boolean

[/thrive_toggles][/thrive_toggles_group]

9. Name six data structure types. [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

  1. Linked lists
  2. Files
  3. Stacks
  4. Queues
  5. Trees
  6. Graphs

[/thrive_toggles][/thrive_toggles_group]

10. What is the difference between a “declaration” and a “definition” of a particular function or variable? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

A declaration involves the type and function of an identifier and describes what the linker requires to reference it. A definition describes what the compiler needs to do to interact with the identifier. Sometimes a declaration provides an initial value, and sometimes the definition provides the value.

[/thrive_toggles][/thrive_toggles_group]

11. What is the difference between an interpreter and a compiler? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

An interpreter executes commands directly, while a compiler converts those commands (the program) from source code to machine code. Compiled programs run faster than interpretive languages and can be used at scale.

  • Interpretive language examples: Basic, Korn Shell, Ruby, Python
  • Compiler language examples: Java, C++

[/thrive_toggles][/thrive_toggles_group]

12. What are the functions of object-oriented design? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

  1. Encapsulation
  2. Polymorphism
  3. Inheritance
  4. Abstraction

[/thrive_toggles][/thrive_toggles_group]

13. What is a real-time operating system? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

A real-time operating system (OS) processes data as it becomes available, without a buffering period.

  • Example of a real-time OS: Controlling factory machinery in real-time. Not necessarily instant, but essentially on-demand.
  • Examples of non-real-time OS: Windows and macOS. Response time is not as important.

[/thrive_toggles][/thrive_toggles_group][blank_space height='0.1em']

2. Data structures & algorithms interview questions and answers

data structures and algorithms

 

 

 

 

 

You need to know Data Structure and Algorithm inside-out.

Yes, you'll learn a lot of new concepts by simply attempting to solve these questions.  I still suggest you first refresh your knowledge of Data Structure and Algorithms before you dive head-first into the questions!

Make sure you can create them from scratch. The questions about them may be basic or not – the more you’re able to create them from scratch, the more easily you can answer any interview question about them, whether basic or not so basic.

How to approach any technical programming question

  1. Ask questions.
  2. Create an algorithm.
  3. Write “Pseudo” code first.
  4. Write your code without rushing.
  5. Test your code – thoughtfully fix mistakes.

(This is the process outlined in the classic Cracking the Coding interview by Gayle Laakmann)

Database questions: The Top 7

 

 

 

 

Coding for databases might involve using languages such as Python, Java, and C# to build and implement web-based, cloud-based, and mobile applications that individuals and organizations can use to interact with collections of information.

Not every programming career will require expertise in database management systems.

But it doesn’t hurt to learn the major concepts around databases.

14. Define the word “database.” What kind of interactions does a database management system provide? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

A database is any electronic system that contains data and allows it to be used, accessed, updated, and processed.

Database management systems (DBMS) allow administrators, applications, software, and end users to interact with the data stored on the database.

[/thrive_toggles][/thrive_toggles_group]

15. How do database management systems improve on the functionality of file-based systems? [thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

A file-based system may be interacted with directly by users, but not necessarily concurrently. Data-based management provides mediation between the file system and the application programming interfaces (APIs) being used and is more likely to facilitate multiple users at once. However, these users cannot change the same data at the same time.

[/thrive_toggles][/thrive_toggles_group]

16. What are the three main types of database technology?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

  1. Structure/data: Useful when writing a program that needs to store, manipulate, or read data—but where a full database implementation is not desirable.
  2. Navigational: Navigational databases are associated with hierarchical or network models. This describes a database where objects are processed iteratively, one by one.
  3. SQL/relational: This stands for “structured query language.” Used to retrieve or update information in a database.

[/thrive_toggles][/thrive_toggles_group]

17. What is normalization used for?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Normalization reorganizes data to eliminate redundancy and save disk space. It does so by creating multiple tables and outlining the relationships between them.

[/thrive_toggles][/thrive_toggles_group]

18. What is the difference between DDL and DML?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

DDL stands for “data definition language.” It specifies the structure of a database. DML stands for “data manipulation language” and refers to how data is to be retrieved or modified from said database.

[/thrive_toggles][/thrive_toggles_group]

19. Why is database partitioning necessary?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Partitioning improves efficiency and data availability and minimizes data loss by creating separate, more stable, and more available separate filesystems. Partitioning allows for parallel processing or separating partitions that need to be accessed more or less often.

[/thrive_toggles][/thrive_toggles_group]

20. What is an entity—and what is an entity set?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]An entity is a discrete object or data point, such as a person or place. An entity set groups entities of the same type.

In Java, an entity is an instance of a class. For example: Class = “car.” Instance/entity = “Cadillac CTS.”[/thrive_toggles][/thrive_toggles_group][blank_space height='0.1em']

Array Coding Interview Questions

Array

 

 

 

 

Arrays are the most common data structure in programming—and a vital component in determining how information is accessed. If you have variables as the fundamental building blocks, arrays are the next step up.

It's one of the darling topics of interviewers and you'll hear a lot of questions about arrays in any coding interview, e.g. reversing an array, sorting the array, or searching elements on the array.

The key benefit of an array data structure is that it offers fast O(1) search if you know the index, but adding and removing an element from an array is slow because you cannot change the size of the array once it’s created.

In order to create a shorter or longer array, you need to create a new array and copy all elements from old to new.

[thrive_text_block color=”orange” headline=””]The key to solving array-based questions is having a good knowledge of array data structure as well as basic programming constructors such as loop, recursion, and fundamental operators. [/thrive_text_block]

Here are the top 12 questions about arrays you're likely to get asked at your coding interview:

21. How would you check whether an array contains only digits?

22. How would you go about finding all the permutations of a given array?

23. How do you find the missing number in a given integer array of 1 to 100? (Solution)

24. How do you find the duplicate number on a given integer array? (Solution)

25. How do you find the largest and smallest number in an unsorted integer array? (Solution)

26. How do you find all pairs of an integer array whose sum is equal to a given number? (Solution)

27. How do you find duplicate numbers in an array if it contains multiple duplicates? (Solution)

28. How are duplicates removed from a given array in Java? (Solution)

29. How is an integer array sorted in place using the quicksort algorithm? (Solution)

30. How do you remove duplicates from an array in place?(Solution)

31. How do you reverse an array in place in Java? (Solution)

32. How are duplicates removed from an array without using any library? (Solution)[blank_space height='0.1em']

Trees – The Top 15 Interview Questions and Answers

Binary Tree

 

 

 

 

The following three categories—trees, graphs, and lists—are similar in some fundamental ways, but they still require some specialized knowledge that you might have to call upon during your interview. How well do you know your way around linear and nonlinear data structures?

In Java, trees contain packages that describe how to manipulate lists.

All information in the real world cannot be represented in linear fashion, and that’s where tree data structure helps.

Tree data structure is a data structure that allows you to store your data in a hierarchical fashion. Depending on how you store data, there are different types of trees, such as a binary tree, where each node has, at most, two child nodes.

Along with its close cousin binary search tree, it’s also one of the most popular tree data structures. Therefore, you will find a lot of questions based upon them, such as how to traverse them, count nodes, find depth, and check if they are balanced or not.

A key point to solving binary tree questions is a strong knowledge of theory, e.g. what is the size or depth of the binary tree, what is a leaf, and what is a node, as well as an understanding of the popular traversing algorithms, e.g. pre-, post-, and in-order traversal.

Here's a list of 15 popular binary tree-based coding questions from software engineer or developer job interviews:

33. What is a binary search tree, and what is it used for?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

A binary tree is a data structure that has two “children” and facilitates the study of data that bifurcates.

[/thrive_toggles][/thrive_toggles_group]

34. Name five types of trees.

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

  1. Binary trees
  2. Binary search trees
  3. AVL trees
  4. B-trees
  5. B+ trees

[/thrive_toggles][/thrive_toggles_group]

35. How is a binary search tree implemented? (Solution)

36. How do you perform preorder traversal in a given binary tree? (Solution)

37. How do you traverse a given binary tree in preorder without recursion? (Solution)

38. How do you perform an inorder traversal in a given binary tree? (Solution)

39. How do you print all nodes of a given binary tree using inorder traversal without recursion? (Solution)

40. How do you implement a postorder traversal algorithm? (Solution)

41. How do you traverse a binary tree in postorder traversal without recursion? (Solution)

42. How are all leaves of a binary search tree printed?(Solution)

43. How do you count a number of leaf nodes in a given binary tree? (Solution)

44. How do you perform a binary search in a given array?(Solution)

Problem-solving with trees:

45. How would you go about mirroring a binary tree?

46. How do you count a number of leaf nodes in a given binary tree?

47. How would you check whether a tree is balanced or not?[blank_space height='0.1em']

Graphs Questions

Graph data structure

 

 

 

 

Graphs are nonlinear data structures composed of multiple nodes and edges, or “vertices.” Graphs can represent networking architecture and can be deployed to solve practical problems. Broadly, they describe directed or undirected relationships.

48. What is depth-first search, or traversal, for graphs?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Depth-first search (DFS) searches graphs and trees by beginning at the root node and following each branch as far as it can before it backtracks. DFS may be used to detect cycles in a graph, to find a path, and to locate strongly connected components.

[/thrive_toggles][/thrive_toggles_group]

49. What is a breadth-first traversal for graphs?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Breadth-first traversal (BFS) examines sibling nodes first and children nodes second. BFS may be used in peer-to-peer networking for finding the shortest path and even in web crawlers used in search engines.

[/thrive_toggles][/thrive_toggles_group]

50. Given a particular graph, how would you determine whether or not it cycles?[blank_space height='0.1em']

Lists questions in coding interview

Linked List Data Structure

 

 

 

 

A linked list is another common data structure that complements the array data structure.

Similar to the array, it is also a linear data structure and stores elements in a linear fashion.

However, unlike the array, it doesn’t store them in contiguous locations; instead, they are scattered everywhere in memory, which is connected to each other using nodes.

[pullquote align=”normal”] A linked list is nothing but a list of nodes where each node contains the value stored and the address of the next node.[/pullquote]

Because of this structure, it’s easy to add and remove elements in a linked list, as you just need to change the link instead of creating the array, but the search is difficult and often requires O(n) time to find an element in the singly linked list.

It also comes in varieties like:

  • a singly linked list, which allows you to traverse in one direction (forward or reverse)
  • a doubly linked list, which allows you to traverse in both directions (forward and backward)
  • a circular linked list, which forms a circle

[thrive_text_block color=”orange” headline=””] In order to solve linked list-based questions, a good knowledge of recursion is important, because a linked list is a recursive data structure.

If you take one node from a linked list, the remaining data structure is still a linked list, and because of that, many linked list problems have simpler recursive solutions than iterative ones.[/thrive_text_block]

Here are 8 of the most common and popular linked list interview questions and their solutions:

51. How do you find the middle element of a singly linked list in one pass? (Solution)

52. How do you check if a given linked list contains a cycle? How do you find the starting node of the cycle (Solution)

53. How do you reverse a linked list? (Solution)

54. How do you reverse a singly linked list without recursion? (Solution)

55. How are duplicate nodes removed in an unsorted linked list? (Solution)

56. How do you find the length of a singly linked list (Solution)

57. How do you find the third node from the end in a singly linked list? (Solution)

58. How do you find the sum of two linked lists using Stack? (Solution)[blank_space height='0.1em']

Algorithmic interview questions

Algorithm

 

 

 

 

Algorithms are often the bread and butter of a coding professional’s career. You know them as the recipe that powers how data is gathered, sorted, and ultimately made useful in other processes.

You can expect algorithm-related questions such as these 7:

59. How is a bubble sort algorithm implemented?(Solution)

60. How is an iterative quicksort algorithm implemented? (Solution)

61. How do you implement an insertion sort algorithm? (Solution)

62. How is a merge sort algorithm implemented?(Solution)

63. How do you implement a bucket sort algorithm?(Solution)

64. How do you implement a counting sort algorithm? (Solution)

65. How is a radix sort algorithm implemented?(Solution)[blank_space height='0.1em']

String Coding Interview Questions

String

 

 

 

 

Along with array and linked list data structures, a string is another popular topic on programming job interviews. I have never participated in a coding interview where no string-based question was asked.

A good thing about the string is that if you know the array, you can solve string-based questions easily, because strings are nothing but a character array.

So all the techniques you learn by solving array-based coding questions can be used to solve string programming questions as well.

Here's my list of 11 frequently asked string coding questions from programming job interviews:

66. How do you print duplicate characters from a string? (Solution)

67. How do you check if two strings are anagrams of each other? (Solution)

68. How do you print the first non-repeated character from a string? (Solution)

69. How can a given string be reversed using recursion? (Solution)

70. How do you check if a string contains only digits? (Solution)

71. How are duplicate characters found in a string? (Solution)

72. How do you count a number of vowels and consonants in a given string? (Solution)

73. How do you count the occurrence of a given character in a string? (Solution)

74. How do you find all permutations of a string? (Solution)

75. How do you reverse words in a given sentence without using any library method? (Solution)

76. How do you check if two strings are a rotation of each other? (Solution)

77. How do you check if a given string is a palindrome? (Solution)

These questions help you improve your knowledge of string as a data structure.

If you feel that your understanding of binary tree coding is inadequate and you can’t solve these questions on your own, I suggest you go back and pick a good data structure and algorithm book.[blank_space height='0.1em']

[blank_space height='0.1em']

3. Programming Interview Logical Questions and Solutions 

Logic Questions

 

 

 

 

 

Apart from data structure-based questions, most of the programming job interviews also ask general logic-based questions, which I’ll describe in this section.

It’s important that you practice these concepts because sometimes they become tricky to solve in the actual interview.

Having practiced them before not only makes you familiar with them, but also gives you more confidence in explaining the solution to the interviewer.

Here are 9 Logic & Math questions:

78. How do you swap two numbers without using the third variable? (Solution)

79. How do you check if two rectangles overlap with each other? (Solution)

80. How do you design a vending machine? (Solution)

Logical Math and Probability Interview Questions

81. What's the formula to check if a number is even?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

num % 2 == 0

[/thrive_toggles][/thrive_toggles_group]

82. What's the formula for the Sum of 1 to N?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

1 + 2 + … + (N – 1) + N = (N+1) * N/2

[/thrive_toggles][/thrive_toggles_group]

83. What's the math formula for the Sum of Geometric Progression?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

20 + 21 + 22 + 23 + … 2n = 2n+1 – 1

[/thrive_toggles][/thrive_toggles_group]

84. Given two fair dices, what is the probability that two dices sum to 8?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

There are 36 (6*6) outcomes for tossing two fair dices, and the outcomes when two dices sum to 8 are:

(2, 6), (3,5), (4,4), (5,3), (6,2);

The probability of two dices sum to 8 is 5/36. Source

[/thrive_toggles][/thrive_toggles_group]

85. There are 100 people standing in a circle. The person standing at 1st position kills the next person (i.e.the person standing at 2nd position) and gives the sword to next to next person (i.e. the person standing at 3rd position ). Which person survives in the end?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

If the total number of people is not in power of 2, then the person at nth position of the Arithmetic Progression defined below will always survive.

Arithmetic Progression ( X ) = a + d * ( n – 1 )
where, a = 3
d = 2
n = Total number of persons – Greatest nth root of 2 less that total number of persons

So for a circle of 100 persons:

X = 3 + 2 * ( 100 -64 – 1 ) = 73

[/thrive_toggles][/thrive_toggles_group]

86. How do you check for Primality? (Solution)[blank_space height='0.1em']

4. Problem solving interview questions for software engineer or coder jobs

Problem Solving

 

 

 

 

Some programming interviews will build to some kind of practical, hands-on, or problem-solving demonstration to see how well you can improvise and bring together the major and minor programming concepts.

Remember that the most important underlying skill for any type of programmer is the ability to think logically.

11 problem-solving questions for you to practice:

87. Here’s an example of a problem involving random selection:

[thrive_toggles_group”][thrive_toggles title=”Example” no=”1/1″] If you had an array of 52 numbers, such as a deck of cards, it would be easy to choose one at random. Your task is to generate a number between 1 and 52 and use that as the index to your array. In other words, derive a system whereby a number or card is chosen at random from a set or deck with all numbers or cards equally probable.[/thrive_toggles][/thrive_toggles_group]

88. Here’s a more difficult variation:

[thrive_toggles_group”][thrive_toggles title=”Example” no=”1/1″]

Imagine you can neither see the whole set at once nor store it. In other words, you’re not told how many total numbers there will be, and you are shown only one number at a time. You cannot store all the numbers you are shown, and you are only told when you’ve seen the final number of the set.

If you are allowed to store two numbers at most, can you respond with a random number, chosen in an equiprobable manner, from that one-at-a-time set or stream immediately upon being told the stream is complete?

[/thrive_toggles][/thrive_toggles_group]

89. Here’s how to solve this problem:

[thrive_toggles_group”][thrive_toggles title=”Example” no=”1/1″]

You need store only two numbers: the total count of numbers seen so far, and your current candidate response, selected from the number stream if it were to end at that point.

When you are shown the first number, you have a count of one. Therefore, your candidate response must be the first and only number seen—it has a probability of one out of one. If you are shown a second number, it becomes your new candidate response with a probability of one out of two. Likewise, a third number will become the new candidate response with a probability of one out of three, and so on.

Thus, as each new number is seen, generate a random number between one and the number of data points seen to that point (N). If your random number is equal to N, then keep the number you were just presented with as your new possible response. Otherwise, keep the answer previously saved through this same logic.

You perform this selection update each time you see a new data point. When you are told the stream is done, the saved value is the right response, chosen equiprobably from all the numbers seen. The probability is 1 out of N regardless of how many there were before the stream stopped.

[/thrive_toggles][/thrive_toggles_group]

Here are some other problems to work through:

90. Write an algorithm to find each instance of a given word in a selection of text.

91. Write a program to generate a random number from within a given range.

92. How do you check if a string contains only digits?

93. Given two strings of characters, find the minimum number of changes required to convert string 1 to string 2.

94. How do you count a number of vowels and consonants in a given string?

95. Given a grid where each square has a numerical value, how would you code a solution for finding the lowest-value route from one side of the grid to the other?

Problem-solving questions on scalability

96. Find all documents that contain a list of words

97. Design data structures for a social media network (Solution)[blank_space height='0.1em']

5. Behavioral Programming Interview Questions – How do you fit their culture?

By asking so-called behavioral questions during your programming interview, they're trying to figure out if your personality will fit their company's culture.

If you're arrogant, you get argumentative and defensive quickly when someone criticizes you, or you start blaming others, they'll take that as a reason to reject you for the job.

Soft skills software developer questions – study them!

Though most of your programming interview will be about your coding skills & analytical ability — it's well worth your time to prepare for these “softer” questions. Recruiters will probably ask you about some of the points in your resume as well. So it makes sense to be ready for that, too.

Quick Tip: In our article on soft skills for programmers, we go much deeper into the behavioral attributes you need to succeed in programming interviews – and generally, your career.

The Top 7 Behavioral & Soft Skills Programming Interview Questions

98. What are your weaknesses?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

When they're asking about your weaknesses, give them an actual weakness of yours! Don't give another strength of yours, disguised as a weakness.

This would make them think you're arrogant or egotistical.

Rather, be honest about a weakness you have — but then show them how you're working to overcome that weakness.

[/thrive_toggles][/thrive_toggles_group]

99. What's a recent technical challenge you've faced — and how did you solve it?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

They're judging your process here.

Prepare a situation you had, in which you solved a problem through a process.

It might be an error you at first couldn't solve. But you show them your process of how in the end, you managed to debug  it.

Maybe you went to Google — but Google didn't find anything.

Then you went to Stack Overflows. Then you went to some of the blogs you know, you watched YouTube videos. Maybe you still couldn't find the answer.

So maybe you went to your mentor.

Your network.

Maybe finally you got to talk to the creator of the stack or the open source library. And you finally solved the problem.

This is how you show them what you can do for them, by using your amazing problem-solving process for their company.

[/thrive_toggles][/thrive_toggles_group]

100. What have been your failures, and how do you deal with failure in general?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Again, be honest about a real failure you've experienced. Then you can paint yourself in a positive light by showing how you've bounced back from that failure and how you're making sure the same won't happen again.

It'll show them your strength of character.

[/thrive_toggles][/thrive_toggles_group]

101. Why do you believe you're a good fit for this job?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

This is a great place to give your elevator pitch.

Even if it's not asked, you can answer this question: Maybe on your way out, if someone's walking you out.

It's about the why. You have to sell them on the why. If you've ever watched Simon Sinek's video, it's much like that.

The why, how, and what.

[/thrive_toggles][/thrive_toggles_group]

102. What's the greatest knowledge you've gained from a past experience?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

This question revolves around a specific point on your resume.

This is where you have a great opportunity to sell some of the soft skills you might have learned.

Or if you just got done with a strength and weaknesses question, relate back to the weakness, and talk about the strengths that you were just talking about.

Regardless, this behavioral programming interview question is where you can sell what you've learned and why you believe now you're prepared for this job because of what you've learned in the past and how that will help you here and now.

[/thrive_toggles][/thrive_toggles_group]

103. How do you handle conflict with co-workers?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

What the interviewers are looking for here is that you can prove you can work well with people, aren't petty — and if conflicts happen, you're both resilient and proactive in solving the problem.

So instead of blaming and complaining, you're taking the lead. You're acknowledging you might be partly responsible for the conflict, but you're not being weak either.

[/thrive_toggles][/thrive_toggles_group]

104. General “small talk” questions

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

You might get to small talk with the interviewer. Here it's important not to reveal anything that they'd use to immediately disqualify you.

Don't talk about:

  • Politics
  • Religion
  • How you think about others of different cultural backgrounds

[/thrive_toggles][/thrive_toggles_group]

‘Weird’ Common Programming Interview Questions they won’t stop asking

Sometimes, the interviewers will ask you something slightly “cringe” — cliché questions they got from who-knows-where.

They won't really help them assess candidates in the way they think they do. But they're sometimes still asking them.

Have a satisfying answer prepared and you'll be able to dodge these unnerving, but still common questions.

105. Where do you see yourself in 5 years?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Paint the picture of how you'll still be working for their company, growing it in all sorts of ways.

Never talk about how you're considering other options for your future.

[/thrive_toggles][/thrive_toggles_group]

106. What was your salary at your previous job?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Here they're trying to see if you're going to give up proprietary information to someone else.

When you're asked this question, say something like “I'd prefer not to reveal my previous salary right now because that's proprietary information.”

[/thrive_toggles][/thrive_toggles_group]

107. What salary do you want for this job?

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

If the interviewer asks you about what salary you want in the job you're applying for, don't answer the question directly. What the question really is asking is if you think of yourself above the company.

Rather say something like: “I feel that I'd like to know more about the company and see how we like each other before we discuss salary. And salary's not the most important thing I'm looking for.”

After all, you'll later have to negotiate your salary as part of your overall compensation package, anyway.

[/thrive_toggles][/thrive_toggles_group]

Brain Teaser Interview Questions

These are tricky questions that can be logically solved. They're not directly programming questions, but they're supposed to show your interviewers that you can think on your feet and are smart enough to quickly solve the puzzles thrown at you.

108. You have nine balls. Eight are of the same weight, one is heavier. You're given a scale which tells you only whether the left side or the right side is heavier. Find die heavy ball in just two uses of the scale.

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Divide the balls into sets of three. After weighing once, you'll know which has the heavy ball.

(with N balls, where N is divisible by 3, weighing once gives us a set of N/3 balls with the heavy ball.)

For the final set of three balls, simply repeat the process: Put one ball off to the side an weigh two. Pick the heavier of the two. (Or, if the balls are the same, pick the third one)

[/thrive_toggles][/thrive_toggles_group]

109. There's a building of 100 floors. If an egg drops from the Nth floor or above, it'll break. If it's dropped from any floor below, it won't break. You're given two eggs. Find N, while minimizing the number of drops for the worst case.

[thrive_toggles_group”][thrive_toggles title=”Answer” no=”1/1″]

Solve for X in: X + (X-1) + (X-2) + … + 1 = 100.

X (X + 1) / 2 = 100 -> X = 14.

We go to floor 14, then 27, then 39, … This takes 14 steps in the worst case.

[/thrive_toggles][/thrive_toggles_group][blank_space height='0.1em']

Coding Interview Success

Your next step to rocking your coding interview

These coding, data structure, algorithm, logic and behavioral questions are the ones you need to know to successfully interview with any company — big or small, for any level of programing job.

This list of coding questions:

  • helps you to start prepping for your interview[blank_space height='1em']
  • gives you good topics to study[blank_space height='1em']
  • lets you find your strengths and weaknesses

Above all, you need good knowledge of data structure and algorithms to succeed in your coding interview. So that’s where you should focus most of your attention. But.. don't neglect those soft skills either!

Wishing you all the best for your programming interview,

Sincerely,

John

For more information about how to succeed on your journey to becoming a highly paid software developer, discover the 5 learning mistakes programmers make: