Data Structures & AlgorithmsHardFlipkart/Uber OA · placement
An array of size 9 holds the numbers 1..9, except that one number is missing and one number appears twice: [6, 5, 1, 3, 4, 7, 2, 8, 2]. Using the sum and the sum of squares (or XOR tricks), what are the repeated and the missing numbers?
- A. repeated 9, missing 2
- B. repeated 2, missing 9
- C. repeated 2, missing 1
- D. repeated 2, missing 10
Correct answer: B. repeated 2, missing 9
Σ expected − Σ actual = missing − repeated = 7, and Σ squares gives missing² − repeated² = 77, so missing + repeated = 11. Solving: repeated 2, missing 9.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Overlapping versus non-overlapping substring counts. What is printed? python s, p = "aababaaabbba", "aba" over = sum(1 for i in…
- Bars of width 1 have heights [2, 3, 1, 5, 2, 1, 1, 6]. What is the area of the largest rectangle that fits under the histogram (computed…
- For an array of n elements, how many contiguous subarrays are there, and how many subsequences (including the empty one)?
- A monotonic deque reports the maximum of every window of size 3 in [19, 6, 7, 16, 10, 2, 12, 8, 17]. What is the SUM of all reported…
- Two pointers start at both ends of the sorted array [3, 4, 5, 6, 8, 17, 18, 23, 26, 27]. How many pairs (i < j) have a[i] + a[j] ≤ 40?…
- What does this loop-counting code print? (Python) python n, c = 20, 0 i = n while i > 0: for j in range(i): c += 1 i //= 2 print(c)