Problem
Ask
Submissions

Problem: Two Sum III - Data structure design

Easy
15 min
Understand how to design and implement a custom TwoSum data structure that efficiently handles a stream of numbers and checks if any pair sums to a specific value. This lesson guides you through constructing methods to add numbers and find target sums, helping you develop practical skills for coding interviews.

Statement

Design a data structure that takes in a stream of numbers and can check if any two numbers add up to a specific value.

Implement the TwoSum class with the following constructor and methods:

  • Constructor: Sets up the TwoSum object with an empty list at the start.

  • void add(int number): Adds a new number to the list.

  • boolean find(int value): Returns TRUE if any two numbers in the list add up to the given value. If not, it returns FALSE.

Constraints:

  • 105-10^5 \leqnumber 105\leq 10^5

  • 231-2^{31} \leqvalue 2311\leq 2^{31} -1

  • At most, 10410^4 calls will be made to add and find methods.

Problem
Ask
Submissions

Problem: Two Sum III - Data structure design

Easy
15 min
Understand how to design and implement a custom TwoSum data structure that efficiently handles a stream of numbers and checks if any pair sums to a specific value. This lesson guides you through constructing methods to add numbers and find target sums, helping you develop practical skills for coding interviews.

Statement

Design a data structure that takes in a stream of numbers and can check if any two numbers add up to a specific value.

Implement the TwoSum class with the following constructor and methods:

  • Constructor: Sets up the TwoSum object with an empty list at the start.

  • void add(int number): Adds a new number to the list.

  • boolean find(int value): Returns TRUE if any two numbers in the list add up to the given value. If not, it returns FALSE.

Constraints:

  • 105-10^5 \leqnumber 105\leq 10^5

  • 231-2^{31} \leqvalue 2311\leq 2^{31} -1

  • At most, 10410^4 calls will be made to add and find methods.