Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The insertion sort is applied to [3, 1, 2]. Count the total number of element moves (each shift of an element one place to the right is one move).
- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
Insertion sort shifts 3 right when inserting 1 (one move), then shifts 3 when inserting 2 (one more move), totalling 2 moves.
More Coding Interview Problems questions
- Problem: Heap-indexed binary tree with 10 nodes (node i has children 2i and 2i+1 when ≤ 10). How many nodes lie at depth 2 (root at depth…
- Problem: In the sorted array [−3, −1, 0, 1, 2, 3], how many pairs of distinct positions (i < j) have a sum of exactly 0?
- Problem: What is C(10, 3) modulo 7?
- Problem: How many prime numbers lie strictly between 100 and 150?
- Problem: The number of decimal digits in 100! is what value?
- Problem: What is gcd(462, 1071)?