Problem
Ask
Submissions

Problem: Two Sum Less Than K

Easy
15 min
Explore how to find the maximum sum of two elements in an array that is less than a given value k. This lesson teaches you to use sorting and efficient search methods like two pointers to solve problems with sum constraints and optimize your approach.

Statement

Given an array of integers, nums, and an integer k, find the maximum sum of two elements in nums less than k. Otherwise, return 1−1 if no such pair exists.

Constraints:

  • 11\leq nums.length 100\leq100

  • 11\leq nums[i] 103\leq 10^3

  • 11\leq k 103\leq 10^3

Problem
Ask
Submissions

Problem: Two Sum Less Than K

Easy
15 min
Explore how to find the maximum sum of two elements in an array that is less than a given value k. This lesson teaches you to use sorting and efficient search methods like two pointers to solve problems with sum constraints and optimize your approach.

Statement

Given an array of integers, nums, and an integer k, find the maximum sum of two elements in nums less than k. Otherwise, return 1−1 if no such pair exists.

Constraints:

  • 11\leq nums.length 100\leq100

  • 11\leq nums[i] 103\leq 10^3

  • 11\leq k 103\leq 10^3