Here is the complete problem statement, examples, constraints, hints, and solution for the "Coding - Number of Ways to Earn Points" question asked at Uber:
Problem Statement:
You are given an integer array points where points[i] represents the score of the ith player. The scores are guaranteed to be a power of 2 in a strictly increasing order. You are also given an integer k which represents the total points earned by the players. Return the number of ways to distribute points such that the total points is exactly k.
Examples:
Example 1: Input: points = [1, 2, 3], k = 7 Output: 8 Explanation: The possible combinations are:
Example 2: Input: points = [1, 2, 3], k = 3 Output: 3
Constraints:
Hints:
Solution: `python def waysToEarnPoints(points, k): dp = [0] * (k + 1) dp[0] = 1
for point in points:
for i in range(point, k + 1):
dp[i] += dp[i - point]
return dp[k]
points = [1, 2, 3] k = 7 print(waysToEarnPoints(points, k)) # Output: 8 `
This solution uses dynamic programming to build up the number of ways to earn points from 0 to k. It iterates through each point value and updates the dp array by adding the number of ways to earn points up to i - point to the current dp[i] value. The final result is stored in dp[k], which represents the number of ways to earn exactly k points.