Tap here to switch tabs
Problem
Submissions

Problem: Two Sum Less Than K

Two Sum Less Than K asks you to choose two elements from an array and return their largest possible sum below a given threshold, or negative one if no pair qualifies.

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:

  • 1≤1\leq nums.length ≤100\leq100

  • 1≤1\leq nums[i] ≤103\leq 10^3

  • 1≤1\leq k ≤103\leq 10^3

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Two Sum Less Than K

Two Sum Less Than K asks you to choose two elements from an array and return their largest possible sum below a given threshold, or negative one if no pair qualifies.

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:

  • 1≤1\leq nums.length ≤100\leq100

  • 1≤1\leq nums[i] ≤103\leq 10^3

  • 1≤1\leq k ≤103\leq 10^3