ProgrammingHardTCS NQT · Accenture pattern
What will be the output of the following pseudocode (finding the kth smallest element by sorting)? (Arrays are indexed from 0.)
What will be the output of the following pseudocode (finding the kth smallest element by sorting)? (Arrays are indexed from 0.)
Integer arr[6] = {7, 10, 4, 3, 20, 15}
Integer k = 3
sort arr ascending
Print arr[k - 1]- A. 4
- B. 7
- C. 10
- D. 3
Correct answer: B. 7
Sorted ascending, arr becomes {3, 4, 7, 10, 15, 20}; the 3rd smallest (index k-1=2) is 7.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode (number of ways to climb n stairs, taking 1 or 2 steps at a time)? Function…
- What will be the output of the following pseudocode (product of array except self, without using division)? (Arrays are indexed from 0.)…
- What will be the output of the following pseudocode (how many output rows a zigzag string conversion uses)? Function numRowsUsed(String s…
- What will be the output of the following pseudocode (counting islands in a grid using flood-fill DFS)? (Grids are indexed from 0.) Integer…
- What will be the output of the following pseudocode (summing positive and negative matrix entries separately)? Integer mat[3][3] = {{1…
- What will be the output of the following pseudocode (counting distinct pairs whose difference is k)? (Arrays are indexed from 0.) Integer…