Data Structures & AlgorithmsHardTCS NQT · Infosys
Two people in a circle of 5 are numbered 1 to 5 and eliminated by repeatedly removing every second person (starting by removing person 2). Which person number survives?
- A. 3
- B. 4
- C. 1
- D. 5
Correct answer: A. 3
Removing every second person in a circle is the Josephus problem with k = 2; checking the first few eliminations by hand (2, 4, 1, 5) confirms the survivor.
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
- How many index pairs i < j in the array [1, 2, 3, 4, 5, 6] satisfy gcd(a[i], a[j]) = 1 and a[i] + a[j] is odd?
- What is the number of elements remaining in the list after deleting each element that is smaller than the element immediately before it…
- How many NON-EMPTY subsets of [3, 6, 9, 12, 15, 4, 8, 11] (chosen by index, so equal values are different elements) have a sum divisible…
- How many subsets of {1, 2, 3, 4, 5, 6, 7, 8} have sum exactly 15? (The empty set is excluded, and each value is used at most once.)
- How many arrays of length 4 with values from {1, 2, ..., 3} have no two adjacent elements equal?
- Each step adds 1 to one element of [2, 2, 2, 5, 5, 1]. What is the minimum total number of steps so that every element becomes distinct?…