Coding Interview Club

Prepare for coding interviews in simple and structured steps

Important Problems on Sorting and Searching

  1. Merge two sorted arrays A and B in sorted order. A has enough locations in the end to hold the elements of B.
    • No extra buffer should be used.
    • Every element should be shifted from its current position in A, at most 1 time.
    • Hint:
      • Start filling from the end of A.
  2. Sort an array of Strings. All anagrams should be next to each other.
    • Hint:
      • Approach 1: Modify the comparator to indicate that two anagrams are equal, and then sort.
      • Approach 2: Using a hash table that maps from the sorted version of a word to a list of its anagrams.
  3. How will you sort a very big file (approx 20GB) with one String per line
    • Hint:
      • Don't bring all data into memory.
      • Use external sort: Divide into chunks, sort the chunks and merge the sorted chunks.

Refer to individual problems under corresponding problem category for solutions.

Back to Top