Data Structures & AlgorithmsHardGATE CS · ICPC regional
A singly linked list contains the people 1 to 12 in a circle. Starting from person 1, every 4th person is removed (the count starts at 1) until one remains. Which person survives?
- A. 2
- B. {C+7}
- C. 4
- D. 1
Correct answer: D. 1
Simulate with a circular list: rotate k-1 times then remove. An off-by-one in the rotation count changes 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 contiguous subarrays of [3, 4, -7, 1, 2, -6] have a sum of exactly zero?
- In the array [1, 4, 6, 8, 13], the minimum absolute difference between two distinct elements is d. How many index pairs i < j have |a[i]…
- How many strings of length 4 over the alphabet {a, b} contain the letter a somewhere before a b (that is, contain 'a' followed later by…
- What is the edit distance (Levenshtein distance with insertion, deletion and substitution each costing 1) between intention and execution?
- What is the length of the longest common subsequence of AGGTAB and GXTXAYB (letters need not be contiguous)?
- What is the rank (1-based, in lexicographic order) of the string cab among all permutations of the letters a, b, c?