Company: Salesforce
Difficulty: medium
Saving the Galaxy Problem Description In a distant future where space travel is commonplace, a group of adventurers embarks on a mission to save the galaxy from an imminent threat. Along their journey, they encounter space stations offering vital supplies, each with its own price in credits. The adventurers have a limited amount of credits to spend on these supplies. Given an array representing the prices of the available supplies and the number of credits the adventurers possess, devise a method to determine the maximum number of supplies they can purchase. Examples Example 1: Input: costs = [1,3,2,4,1], credits = 7 Output: 4 Explanation: Adventurers can buy supplies at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7. Example 2: Input: costs = [10,6,8,7,7,8], credits = 5 Output: 0 Explanation: Adventurers cannot afford any of the supplies. Example 3: Input: costs = [1,6,3,1,2,5], credits = 20 Output: 6 Explanation: Adventurers can buy all the supplies for a total price of 1 + 6