Arrays, strings and hash maps interview questions
Hash sets and maps for seen-before checks, complements, counting keys and prefix sums; in-place array tricks; what lists and dicts really cost.
– interview-ready · 14 questions in this topic
– of 14 tried
Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.
Questions
- Spot the first repeated badge at the doorPredict
- Two gift prices that hit the budget exactlyFill the blank
- Group tile racks that hold the same lettersPredict
- Count sales stretches that add up to a targetPredict
- Longest run of consecutive ticket numbersPick the fix
- Find the value that fills more than half the listPredict
- Each shelf's product of all the other shelvesSpot the bug
- Shift a playlist k places to the right, in placeOrder the steps
Practise this topic
Flashcards · 24
Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.
Quick quiz · 14 questions
One exercise per question, checked as you go. Needs JavaScript.
Mock interview · 2 sets
Timed, out loud, then tick what you covered. Needs JavaScript.
Fix this PR · 1 review
Review a diff like a senior: flag the lines you'd comment on. Needs JavaScript.
Quick facts
Recall the answer first, then tap Show to check.
x in some_listScans the list from the front, so it costs O(n) per check. A set or dict answers the same question in O(1) on average.
Dict order
Since Python 3.7, a dict keeps keys in the order they were first inserted. Updating a value keeps its position.
list.appendcostAmortized O(1): the list over-allocates, so most appends write into spare room and only the occasional one copies.
hash(-1)in CPythonReturns -2, because -1 is reserved as an error signal inside CPython's C code. Every other small int hashes to itself.
Kotlin
HashMapvsLinkedHashMapmutableMapOf()returns a LinkedHashMap, which keeps insertion order; a plain HashMap does not promise any order.
Printable cheat sheet · Review your weak spots in this topic
Share your progress
Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license