All 53 questions

  1. Compare merge sort, quicksort, and heap sort, including their time complexities.

    Asked in 6 of 374 interviews · last asked Oct 9 · Concept · Junior

    Show answer

    Standard merge sort takes O(n log n) time in the best, average, and worst cases. Quicksort takes O(n log n) in the best and average cases, but O(n²) in the worst case. Heap sort takes O(n log n) on average and in the worst case.

    • Merge sort can preserve equal elements' order, making it stable; array implementations usually need O(n) extra space.
    • Typical recursive quicksort uses O(log n) stack space on average, but O(n) in the worst case.
    • Quicksort is usually not stable; randomized pivots reduce the risk of poor splits.
    • Heap sort is not stable, uses O(1) extra space, and guarantees O(n log n) worst-case time.

    What the interviewer checks: The interviewer checks whether you can compare time guarantees, memory use, and stability when choosing a sorting algorithm.

    Other ways it was asked
    • “What is the time complexity of merge sort and quicksort?”
    • “What are the time complexities of bubble sort and merge sort?”
    • “What is the time complexity of merge sort?”
  2. Implement binary search, explain when it applies, and give its time complexity.

    Asked in 6 of 374 interviews · last asked Sep 14 · Concept · Junior

    Show answer

    Binary search finds a target in a sorted array by checking the middle and repeatedly halving the search range. It needs sorted data and constant-time access by index for O(log n) worst-case time. An iterative implementation uses O(1) extra space.

    • The comparison order must match the array's sort order.
    • After each comparison, discard the half that cannot contain the target.
    • Return -1 if the target is missing, including for an empty array.
    • With duplicates, this version returns any matching index, not necessarily the first.
    Python
    def binary_search(arr, target):
        # arr must be sorted in ascending order.
        low, high = 0, len(arr) - 1
        while low <= high:
            mid = low + (high - low) // 2
            if arr[mid] == target: return mid
            if arr[mid] < target:
                low = mid + 1
            else: high = mid - 1
        return -1

    What the interviewer checks: The interviewer checks whether you handle search boundaries correctly and explain the requirements and cost of binary search.

    Other ways it was asked
    • “What is the time complexity of binary search?”
    • “What is binary search, and when can it be used?”
    • “What is the binary search algorithm, and when can it be used?”
  3. What sorting algorithms are you familiar with?

    Asked in 3 of 374 interviews · last asked Aug 26 · Concept · Junior

    Other ways it was asked
    • “What other sorting algorithms do you know?”
    • “What sorting algorithms are you aware of?”
  4. What is the time complexity of insertion sort?

    Asked in 3 of 374 interviews · last asked Aug 27 · Concept · Junior

    Other ways it was asked
    • “What is the time complexity of sorting an array?”
    • “What is the time complexity of heap sort?”
    • “What is the time complexity of bubble sort?”
  5. Write a C++ program that takes 15 random numbers, sorts them, and prints them.

    Asked in 2 of 374 interviews · last asked Aug 12 · Write code · Junior

    Other ways it was asked
    • “Write a C++ program that generates 10 random numbers, sorts them in ascending order, and prints them.”
    • “Write a C++ program that stores 15 random names in an array, sorts them alphabetically, and prints them.”
    • “Write a Java program that takes 15 random numbers, sorts them, and prints them.”
  6. How would you use a comparator to sort an array, what is a comparator, and what is the time complexity?

    Asked once · last asked Apr 8 · Write code · Junior

  7. Given a sorted array that has been rotated, how would you find the index of a target value in O(log n)?

    Asked once · last asked Apr 11 · Write code · Junior

  8. Can you write a binary search implementation in JavaScript?

    Asked once · last asked Jun 24 · Write code · Junior

  9. Which data structure would you choose to search for a number: an array, a linked list, or an ArrayList?

    Asked once · last asked Nov 17 · Concept · Junior

  10. Why is it mandatory for data to be ordered before running a binary search? What failures occur if the collection is unsorted?

    Asked once · last asked Aug 10 · Concept · Junior

  11. How would you break down the performance gap between quicksort’s best-case and worst-case scenarios? What data patterns cause that variance?

    Asked once · last asked Aug 10 · Concept · Junior

  12. How would you sort an array of objects by salary?

    Asked once · last asked Aug 10 · Write code · Junior

  13. Given an array of distinct integers sorted in ascending order and a target integer, implement a function to search for the target in the array. Return its index if it exists; otherwise, return -1.

    Asked once · last asked Aug 11 · Write code · Junior

  14. Can you create me a C++ program that takes in 10 random names, alphabetizes them, and prints them on the screen?

    Asked once · last asked Aug 12 · Write code · Junior

  15. What is the average time complexity for searching an element in binary search, and what are its constraints?

    Asked once · last asked Aug 20 · Concept · Junior

  16. How do sorting algorithms compare in time complexity, and is there a universally fastest one?

    Asked once · last asked Aug 20 · Concept · Mid-level

  17. How do bubble sort, insertion sort, merge sort, and quicksort compare in worst-case time complexity?

    Asked once · last asked Sep 5 · Concept · Junior

    Other ways it was asked
    • “Which of bubble sort, insertion sort, merge sort, and quicksort has the worst-case time complexity?”
  18. Explain merge sort and implement it.

    Asked once · last asked Sep 5 · Write code · Junior

  19. Solve the Codeforces problem Magic Powder 1.

    Asked once · last asked Sep 6 · Write code · Junior

  20. Implement the bucket sort approach in code to find the k most frequent elements in an array.

    Asked once · last asked Sep 9 · Write code · Mid-level

  21. What is the time complexity of sorting the characters in a string and comparing adjacent characters?

    Asked once · last asked Oct 1 · Concept · Junior

  22. How does Arrays.sort behave differently for Integer arrays versus String arrays?

    Asked once · last asked Oct 2 · Concept · Junior

  23. Which sorting algorithm does Java's Arrays.sort use for object arrays?

    Asked once · last asked Oct 2 · Concept · Junior

  24. How can you sort Person objects by age in descending order in a single line?

    Asked once · last asked Oct 2 · Write code · Junior

    Other ways it was asked
    • “How would you compare Person objects by age when sorting them in descending order in Java?”
  25. What is bubble sort, and when would you use it?

    Asked once · last asked Oct 4 · Concept · Junior

  26. Can you implement an algorithm to sort a list in O(n) time?

    Asked once · last asked Oct 5 · Write code · Mid-level

  27. How would you sort strings that begin with A followed by a number so the smallest number comes first?

    Asked once · last asked Oct 13 · Write code · Junior

  28. How would you search for a target value in an n × n matrix whose rows and columns are sorted?

    Asked once · last asked Oct 15 · Write code · Mid-level

  29. How can you use both the row-sorted and column-sorted properties of a matrix to make searching more efficient?

    Asked once · last asked Oct 15 · Concept · Mid-level

  30. Can you efficiently search a matrix with sorted rows and columns without applying binary search separately to each row or column?

    Asked once · last asked Oct 15 · Concept · Mid-level

  31. What are the two decision conditions in the search algorithm for a row- and column-sorted matrix, and what are its time and space complexities?

    Asked once · last asked Oct 15 · Concept · Mid-level

  32. Write code to sort an array.

    Asked once · last asked Apr 8 · Write code · Junior

  33. How would you search for an item in a Java collection?

    Asked once · last asked May 25 · Concept · Junior

  34. Which time complexity is more efficient for sorting as input size grows: O(n²) or O(n log n)?

    Asked once · last asked May 25 · Concept · Junior

    Other ways it was asked
    • “Which sorting algorithm has better time complexity: O(n²) or O(n log n)?”
  35. Why is O(n log n) more efficient than O(n²), and which sorting algorithm divides an array into parts?

    Asked once · last asked May 25 · Concept · Junior

  36. Which sorting algorithm divides an array into parts and then merges them?

    Asked once · last asked May 25 · Concept · Junior

  37. How would you sort a list of integers in ascending order?

    Asked once · last asked Jun 17 · Write code · Junior

  38. Given a list of numbers and a number to find, what kind of search would you use?

    Asked once · last asked Nov 17 · Concept · Junior

  39. What is the difference between binary search and linear search?

    Asked once · last asked Nov 17 · Concept · Junior

  40. What are sorting algorithms?

    Asked once · last asked Aug 11 · Concept · Junior

  41. Why do sorting algorithms play an important role in data science and software development?

    Asked once · last asked Aug 11 · Concept · Junior

  42. How can sorting algorithms significantly reduce execution time?

    Asked once · last asked Aug 11 · Concept · Junior

  43. What is the time complexity of linear search on an array of size n?

    Asked once · last asked Aug 20 · Concept · Junior

    Other ways it was asked
    • “What is the time complexity of your linear search approach for an array of size n?”
  44. How would you explain quick sort?

    Asked once · last asked Aug 20 · Concept · Junior

  45. Can you come up with a quicksort algorithm?

    Asked once · last asked Aug 31 · Write code · Mid-level

  46. What is the worst-case time complexity of quicksort, and when does it occur?

    Asked once · last asked Sep 4 · Concept · Junior

    Other ways it was asked
    • “What is the worst case of Quick Sort?”
  47. What are common applications of binary search?

    Asked once · last asked Sep 4 · Concept · Junior

  48. Which sorting algorithm would you use to order elements by frequency when finding the two most frequent elements?

    Asked once · last asked Sep 10 · Write code · Junior

  49. How would you sort an array using a loop?

    Asked once · last asked Oct 6 · Write code · Junior

  50. What ordering does a default string sort produce for strings formatted as A followed by a number?

    Asked once · last asked Oct 13 · Concept · Junior

  51. What type of algorithmic approach is binary search?

    Asked once · last asked Oct 15 · Concept · Junior

  52. What is the core idea behind binary search?

    Asked once · last asked Oct 15 · Concept · Junior

  53. How would you search for 14 in a row- and column-sorted matrix, starting from the first row?

    Asked once · last asked Oct 15 · Scenario · Junior

    Other ways it was asked
    • “How would you trace a search for 14 in a row- and column-sorted matrix, starting from the first row?”

More Data Structures and Algorithms interview questions

How this list is made

Every question here was asked by a real interviewer in a real job interview that a candidate ran MeetAssist in. After the call, the interviewer's questions are pulled from the transcript. Practice sessions, tests, exams and anything that was not a job interview are dropped.

Questions are rewritten so they make sense on their own: names of people, employers and clients are removed, and speech-to-text mistakes are fixed. Small talk, logistics and questions about one candidate's own résumé are left out. Rephrasings of the same question are merged, and the count is the number of different interviews it came up in.

The interviews come from candidates who use MeetAssist, so they lean towards software, data and AI roles: the shares describe these interviews, not every Data Structures and Algorithms interview. Answers to the most asked questions are written and checked by an editor; a "common mistake" is shown only when reviews of real answers in these interviews show it, with the count.

374 interviews, 269 candidates, Sep 2025 to Oct 2026. Updated every month with new interviews.