LearnFrenzy
Sign in Take a free test

Arrays · Exercise 4 of 4

Arrays Arrays Coding Problems

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Array problems asked in placement tests and interviews: second largest, duplicates, rotation, merging sorted arrays, transpose, chunks, moving zeros, the missing number, frequencies and pair sums. Write each one yourself first, then open the solution – every solution was run on Node.js and the output shown is the real output.

Question 1 Medium

Find the second largest distinct value in an array in a single pass, without sorting. Return null if it does not exist.

Question page & discussion
Question 2 Easy

Remove duplicates from [3, 1, 3, 2, 1, 4] keeping the first occurrence order, first with a Set and then without one.

Question page & discussion
Question 3 Medium

Rotate [1, 2, 3, 4, 5, 6, 7] to the right by 3 positions (and handle k larger than the length) using slice, then do it in place with the reversal method.

Question page & discussion
Question 4 Medium

Merge two sorted arrays into one sorted array in O(n + m) time, without calling sort().

Question page & discussion
Question 5 Medium

Transpose a 2 × 3 matrix (rows become columns) and print both matrices row by row.

Question page & discussion
Question 6 Easy

Write chunk(arr, size) that splits an array into groups of the given size (the last group may be smaller), e.g. to show 3 products per row.

Question page & discussion
Question 7 Medium

Move all zeros of [0, 1, 0, 3, 12, 0, 5] to the end in place, keeping the order of the other numbers.

Question page & discussion
Question 8 Easy

An array contains the numbers 1 to n with exactly one missing. Find it using the sum formula, and also with XOR.

Question page & discussion
Question 9 Medium

Count how often each vote appears and print the winner (ties go to the candidate who reached the count first).

Question page & discussion
Question 10 Hard

Return the indexes of the first pair of numbers that add up to the target in one pass, and also list every distinct pair of values with that sum.

Question page & discussion
All exercises doneBack to ArraysRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links