A pricing page wants to show a "save exactly k" badge when one plan costs exactly k more than another.
Write differByK(prices, k) that returns true if there are two different indexes i and j with prices[i] - prices[j] === k, and false otherwise.
Input: prices = [10,25,17,32], k = 15 Output: true
25 - 10 = 15.
Input: prices = [1,5,9], k = 3 Output: false
The differences are 4, 8, and 4.
0 <= prices.length <= 10^50 <= k <= 10^9-10^9 <= prices[i] <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #28 Two Prices Exactly K Apart. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.