Back to Blog
Question CollectionCoding12 min readUpdated Jul 18, 2026

Top 10 FAANG Coding Interview Questions Asked by Amazon and Google

Top 10 Coding Question uses verified RivoHire qbank answers. Start with the strongest short answer, then review tradeoffs, scenarios, mistakes, and interview wording.

Start learning

RivoHire Editorial

Question Collection

CodingTop 10 Coding QuestionCoding Interview Questions

Quick outcome

By the end of this guide, you will:

  • 1. Find the pair of numbers in an array that adds up to a target value.
  • 2. Move all zeroes in an array to the end while preserving the order of non-zero elements.
  • 3. Find the maximum subarray sum in an integer array.
  • 4. Rotate an array to the right by k positions.
  • 5. Merge two sorted arrays into one sorted array.

Coding question collection

Interview Questions With Code Practice

Each question includes the prompt, interview explanation, language tabs, a code-editor style solution, and time and space complexity notes.

Difficulty Distribution

Junior: 10

1. Find the pair of numbers in an array that adds up to a target value.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the pair of numbers in an array that adds up to a target value.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>
#include <stdlib.h>

void findPair(int arr[], int size, int target) {
    for (int i = 0; i < size; i++) {
        for (int j = i + 1; j < size; j++) {
            if (arr[i] + arr[j] == target) {
                printf("%d %d\n", arr[i], arr[j]);
                return;
            }
        }
    }
    printf("No pair found\n");
}

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int target = 9;
    int size = sizeof(arr) / sizeof(arr[0]);
    findPair(arr, size, target);
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(1)

Practice This Question

2. Move all zeroes in an array to the end while preserving the order of non-zero elements.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Move all zeroes in an array to the end while preserving the order of non-zero elements.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>

void moveZeroes(int* nums, int size) {
    int count = 0; // Count of non-zero elements
    for (int i = 0; i < size; i++) {
        if (nums[i] != 0) {
            nums[count++] = nums[i];
        }
    }
    while (count < size) {
        nums[count++] = 0;
    }
}

int main() {
    int nums[] = {0, 1, 0, 3, 12};
    int size = sizeof(nums) / sizeof(nums[0]);
    moveZeroes(nums, size);
    for (int i = 0; i < size; i++) {
        printf("%d ", nums[i]);
    }
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(1)

Practice This Question

3. Find the maximum subarray sum in an integer array.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the maximum subarray sum in an integer array.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>
#include <limits.h>

int maxSubArraySum(int arr[], int n) {
    int max_so_far = INT_MIN, max_ending_here = 0;
    for (int i = 0; i < n; i++) {
        max_ending_here += arr[i];
        if (max_so_far < max_ending_here) {
            max_so_far = max_ending_here;
        }
        if (max_ending_here < 0) {
            max_ending_here = 0;
        }
    }
    return max_so_far;
}

int main() {
    int n;
    scanf("%d", &n);
    int arr[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    printf("%d\n", maxSubArraySum(arr, n));
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(1)

Practice This Question

4. Rotate an array to the right by k positions.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Rotate an array to the right by k positions.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>

void rotate(int* nums, int numsSize, int k) {
    k = k % numsSize;
    if (k == 0) return;
    int temp[numsSize];
    for (int i = 0; i < numsSize; i++) {
        temp[(i + k) % numsSize] = nums[i];
    }
    for (int i = 0; i < numsSize; i++) {
        nums[i] = temp[i];
    }
}

int main() {
    int nums[] = {1, 2, 3, 4, 5, 6, 7};
    int k = 3;
    int numsSize = sizeof(nums) / sizeof(nums[0]);
    rotate(nums, numsSize, k);
    for (int i = 0; i < numsSize; i++) {
        printf("%d ", nums[i]);
    }
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(1)

Practice This Question

5. Merge two sorted arrays into one sorted array.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Merge two sorted arrays into one sorted array.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>

void merge(int arr1[], int n1, int arr2[], int n2, int merged[]) {
    int i = 0, j = 0, k = 0;
    while (i < n1 && j < n2) {
        if (arr1[i] < arr2[j]) {
            merged[k++] = arr1[i++];
        } else {
            merged[k++] = arr2[j++];
        }
    }
    while (i < n1) {
        merged[k++] = arr1[i++];
    }
    while (j < n2) {
        merged[k++] = arr2[j++];
    }
}

int main() {
    int arr1[] = {1, 3, 5};
    int arr2[] = {2, 4, 6};
    int n1 = sizeof(arr1) / sizeof(arr1[0]);
    int n2 = sizeof(arr2) / sizeof(arr2[0]);
    int merged[n1 + n2];
    merge(arr1, n1, arr2, n2, merged);
    for (int i = 0; i < n1 + n2; i++) {
        printf("%d ", merged[i]);
    }
    return 0;
}

Time Complexity

O(n log n)

Space Complexity

O(1) to O(n)

Practice This Question

6. Find the majority element in an array.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the majority element in an array.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>
#include <stdlib.h>

int majorityElement(int* nums, int numsSize) {
    int count = 0, candidate = 0;
    for (int i = 0; i < numsSize; i++) {
        if (count == 0) {
            candidate = nums[i];
        }
        count += (nums[i] == candidate) ? 1 : -1;
    }
    return candidate;
}

int main() {
    int nums[] = {2, 2, 1, 1, 1, 2, 2};
    int size = sizeof(nums) / sizeof(nums[0]);
    printf("%d\n", majorityElement(nums, size));
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(1)

Practice This Question

7. Find the missing number from an array containing values from 1 to n.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the missing number from an array containing values from 1 to n.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>

int findMissingNumber(int arr[], int n) {
    int total = (n * (n + 1)) / 2;
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += arr[i];
    }
    return total - sum;
}

int main() {
    int n;
    scanf("%d", &n);
    int arr[n - 1];
    for (int i = 0; i < n - 1; i++) {
        scanf("%d", &arr[i]);
    }
    printf("%d\n", findMissingNumber(arr, n));
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(1)

Practice This Question

8. Find the duplicate number in an array without modifying the input.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the duplicate number in an array without modifying the input.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>
#include <stdlib.h>

int findDuplicate(int* nums, int numsSize) {
    int slow = nums[0];
    int fast = nums[0];
    do {
        slow = nums[slow];
        fast = nums[nums[fast]];
    } while (slow != fast);

    slow = nums[0];
    while (slow != fast) {
        slow = nums[slow];
        fast = nums[fast];
    }
    return slow;
}

int main() {
    int nums[] = {1, 3, 4, 2, 2};
    int size = sizeof(nums) / sizeof(nums[0]);
    int duplicate = findDuplicate(nums, size);
    printf("%d\n", duplicate);
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(n)

Practice This Question

9. Return the product of array elements except self without using division.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Return the product of array elements except self without using division.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>

void productExceptSelf(int* nums, int numsSize, int* output) {
    int left[numsSize];
    int right[numsSize];
    left[0] = 1;
    right[numsSize - 1] = 1;

    for (int i = 1; i < numsSize; i++) {
        left[i] = left[i - 1] * nums[i - 1];
    }

    for (int i = numsSize - 2; i >= 0; i--) {
        right[i] = right[i + 1] * nums[i + 1];
    }

    for (int i = 0; i < numsSize; i++) {
        output[i] = left[i] * right[i];
    }
}

int main() {
    int nums[] = {1, 2, 3, 4};
    int numsSize = sizeof(nums) / sizeof(nums[0]);
    int output[numsSize];
    productExceptSelf(nums, numsSize, output);
    for (int i = 0; i < numsSize; i++) {
        printf("%d ", output[i]);
    }
    return 0;
}

Time Complexity

O(n)

Space Complexity

O(1)

Practice This Question

10. Find the longest consecutive sequence in an unsorted array.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the longest consecutive sequence in an unsorted array.

I would optimize the approach and explain why the chosen data structure fits.

Mention edge cases before writing code, then finish with time and space complexity.

Syntax Highlighted Code Editor
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int compare(const void *a, const void *b) {
    return (*(int*)a - *(int*)b);
}

int longestConsecutive(int* nums, int numsSize) {
    if (numsSize == 0) return 0;
    qsort(nums, numsSize, sizeof(int), compare);
    int longestStreak = 1, currentStreak = 1;
    for (int i = 1; i < numsSize; i++) {
        if (nums[i] == nums[i - 1]) continue;
        if (nums[i] == nums[i - 1] + 1) {
            currentStreak++;
        } else {
            longestStreak = currentStreak > longestStreak ? currentStreak : longestStreak;
            currentStreak = 1;
        }
    }
    return longestStreak > currentStreak ? longestStreak : currentStreak;
}

int main() {
    int nums[] = {100, 4, 200, 1, 3, 2};
    int size = sizeof(nums) / sizeof(nums[0]);
    printf("%d\n", longestConsecutive(nums, size));
    return 0;
}

Time Complexity

O(n log n)

Space Complexity

O(1) to O(n)

Practice This Question

FAQ

Find the pair of numbers in an array that adds up to a target value.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the pair of numbers in an array that adds up to a target value. In an interview, support it with one tradeoff and one production example.

Move all zeroes in an array to the end while preserving the order of non-zero elements.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Move all zeroes in an array to the end while preserving the order of non-zero elements. In an interview, support it with one tradeoff and one production example.

Find the maximum subarray sum in an integer array.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the maximum subarray sum in an integer array. In an interview, support it with one tradeoff and one production example.

Rotate an array to the right by k positions.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Rotate an array to the right by k positions. In an interview, support it with one tradeoff and one production example.

Merge two sorted arrays into one sorted array.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Merge two sorted arrays into one sorted array. In an interview, support it with one tradeoff and one production example.

Find the majority element in an array.

A strong solution should clarify inputs and edge cases, choose an efficient algorithm, explain time and space complexity, and provide clean implementation steps for: Find the majority element in an array. In an interview, support it with one tradeoff and one production example.

Continue learning

Practice this topic before the interview

Turn the article into spoken practice and get feedback on clarity, confidence, and technical depth.

Start practicing