🔡 Top 3 Array Challenges for Interviews

Oh no… back to Bubble Sort? 🫧

Top 3 Arrays Illustration

Hey friends! 👋

Whenever I talk to people preparing for coding interviews, I hear the same thing:

Arrays? Nobody asks those anymore!

And yet… arrays keep coming back, again and again. They're simple enough to explain under pressure, but tricky enough to filter candidates when the interviewer adds a 😡little twist😡... MU HA HA

Today I'm not going to cover standard techniques like binary search or sorting. Instead, I'll focus on three tasks where the elegant trick is what makes or breaks the solution.

🔹 Problem 1: The Missing Numbers

You're given an array of length n where each element is supposed to be a number between 1 and n. But of course, some numbers go missing, and some appear twice.

Your job: return all the numbers in [1..n] that don't show up in the array.

Example:


Input:  [4,5,6,7,8,6,5,1]
Output: [2,3]
                                    

Super-easy, right? We just need to create an array from 1 to n, make a set, and find the difference:


def findMissingNumbers(nums):
    return list(set(range(1, len(nums) + 1)) - set(nums))
                                    

But here we are creating a new array, which makes our memory complexity O(n). The main challenge here is to do it without additional memory. Are you ready for the solution? 😬

👉 Solution:


def findMissingNumbers(nums):
    for num in nums:
        index = abs(num) - 1

        if nums[index] > 0:
            nums[index] *= -1

    return [i + 1 for i in range(len(nums)) if nums[i] > 0]
                                    

Why is this problem beautiful? Because the optimal way is not to use a set or extra memory, but to work directly inside the array itself.

The key trick is to use the values as “markers” for which indices you've already seen. Once you realize you can mutate the array keeping its structure, the whole problem collapses into a clean O(n) in-place algorithm!

Love in place meme

🔹 Problem 2: Array Rotation

You're given an array and a number k. Shift the array to the right by k positions.

Vitaly, "eaaaaaaaaaaaaaaaaaaasy", right?

Example:


Input:  nums = [1,2,3,4,5,6,7,8], k = 4
Output: [5,6,7,8,1,2,3,4]
                                    

But can you write your solution in linear time? That's the main challenge here!

👉 Solution:


def shift(nums, k):
    real_rotation = k % len(nums)

    def reverse(nums, start, end):
        while start < end:
            nums[start], nums[end] = nums[end], nums[start]
            start += 1
            end -= 1
    
    reverse(nums, 0, len(nums) - 1)
    reverse(nums, 0, real_rotation - 1)
    reverse(nums, real_rotation, len(nums) - 1)
                                    

What makes this fun is that the naive approach (shifting one step at a time) is quadratic. We definitely don't have so much time 😂

But there's a wonderfully elegant linear-time solution, which involves carefully reversing parts of the array.

LOVE PROGRAMMING! No 😂

🔹 Problem 3: Moving the Zeroes

Okay, I promised not to cover "basic two-pointer" problems… but this one is too much of a classic to ignore.

The task: given an array, push all zeroes to the end while keeping the order of the other numbers.

And of course... IN-PLACE!!! Using additional memory could decrease your offer by up to 40% 😂

Example:


Input:  [0,1,0,2,3]
Output: [1,2,3,0,0]
                                    

👉 Solution:


def shiftZeroes(nums):
        zero_index = -1

        for i, num in enumerate(nums):
            # skip first non zero values 
            if zero_index == -1 and num != 0:
                continue
            
            # find first zero value
            if num == 0 and zero_index == -1:
                zero_index = i
                continue
            
            # wait for non-zero value
            if num == 0:
                continue
            
            nums[zero_index] = num
            nums[i] = 0
            zero_index += 1
        
        return nums
                                    

Yes, it's a two-pointer pattern, and yes, it's textbook. Buuuut... DON'T KNOW WHY, I've met this task more often than any other and I think I can resolve it with my eyes closed 😌

It tests whether you can apply a standard technique under pressure. And if you write it cleanly without additional memory and in O(n), you'll earn some instant respect 🤪

Conclusion

Arrays may seem like the most elementary data structure, but interviewers know how to make them interesting. The trick is not always about which algorithm you know - it's about whether you can spot the hidden move that makes the solution optimal.

Published on September 5, 2025 Author: Vitaly