Data Structures & AlgorithmsHardTCS NQT · Infosys
Two numbers are stored as linked lists of digits, least significant digit first: 9 -> 9 -> 9 and 1. Their sum is added digit by digit with carry. How many nodes does the resulting list have?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
999 + 1 = 1000, and the list keeps the final carry as an extra node, giving 4 nodes: 0, 0, 0, 1.
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 [3, 4, 2, 6, 1, 2, 12, 1] have a[i] a[j] = 12?
- How many distinct strings of length 3 are palindromes that occur as subsequences of abcab (of the form x y x with y different from x)?
- What is the length of the longest palindromic subsequence of the string leetcode?
- How many contiguous non-empty substrings of aaabbbaa consist of a single repeated letter?
- What is the sum of the distinct prime divisors of 2310?
- How many positive divisors does 2^5 3^3 5^2 have?