Shortest 11 Problem 210

WorldOfWarcraft  

World Of Warcraft

Ivan is an avid World of Warcraft player. In this game, he plays a main character which gets stronger as the game progresses 
by obtaining experience points. In order to obtain as much experience as possible in a period, he uses a strategy guide which 
tells him how many points he needs to get to the next level. 
For example, if the points needed are 100, 200, 400, 800, he would need a total of 100 experience to reach level 2 (from level 1) 
and then another 200 experience to get to level 3.

He has 0 experience points at the start and he is about to start his gaming session which will reward him a fixed amount of 
experience at the end. In order to judge Ivan's performance in the session, you need to calculate how far he will be from the 
next level after he finishes playing.

Example:
    Given:
    xpNeeded = {100, 200, 400, 800}
    xpReceived = 147
	
    Ivan received 147 experience points which will get him to level 2, and he will need additional 153 (200-(147-100)) experience 
    to get to level 3.
	
Input parameters:
	xpReceived - an integer value representing the amount of experience Ivan has obtained in his session
	xpNeededSize - an integer that tells the size of the xpNeeded array
	xpNeeded - an array of experience points needed to reach each level
	
Constraints:
	xpNeeded array will contain between 1 and 50 elements, inclusive.
	xpNeeded array will be sorted in an increasing order.
	All elements in xpNeeded array will be between 1 and 999999, inclusive.
	xpReceived will be between 0 and the largest element of xpNeeded, exclusive.
	
Return value:
	The amount of experience that's needed to reach the next level.
Class Name:
  WorldOfWarcraft

Method signature:
  public int getExperience(int xpReceived, int xpNeededSize, int[] xpNeeded)

Test Case 1:
  getExperience(84628, 1, {302584}) = 217956

Test Case 2:
  getExperience(521286, 8, {31058,39932,308600,316250,516273,598129,720219,904635}) = 174554

Test Case 3:
  getExperience(455858, 28, {24236,67795,113035,114384,138821,155604,189527,230871,246639,249264,337172,340698,369436,382430,410729,422620,467977,526524,586888,663470,674246,703659,704270,719381,786901,808304,870499,998152}) = 2413

Test Case 4:
  getExperience(915351, 29, {113448,126501,164923,197848,239768,240714,313572,358469,362444,368130,382152,466097,501703,518184,574303,586476,598690,661992,711695,719188,730504,735676,794462,801414,809741,916752,923215,925264,937705}) = 167851

Test Case 5:
  getExperience(603849, 12, {166590,282806,306087,330042,482393,546425,595139,700432,767675,771028,786852,943978}) = 151634

Test Case 6:
  getExperience(245403, 14, {19245,25426,75719,171867,386891,402330,414395,596049,599381,673311,726762,735762,741880,993547}) = 46854

Test Case 7:
  getExperience(692706, 15, {247887,311720,332912,392963,444733,637471,690249,703085,732597,740496,768819,786559,791936,816695,875065}) = 199813

Test Case 8:
  getExperience(286210, 37, {75272,131226,132891,142224,154014,160480,174729,209411,225499,292301,307120,311064,341862,377866,417884,495339,541367,546296,582134,583403,615928,654771,658228,668122,687659,799811,855420,862798,872204,877825,880351,911580,931843,949147,949463,951542,975654}) = 53179

Test Case 9:
  getExperience(73765, 20, {33940,113402,121853,125778,145851,157912,184585,294968,427654,478968,523900,563470,604159,718023,758925,824378,865576,875193,981627,985535}) = 73577

Test Case 10:
  getExperience(254158, 45, {23907,34326,54764,87520,91324,101602,121037,127471,151326,166193,178983,190636,203130,216193,216774,229014,276351,321159,329639,356866,362914,390016,397618,401257,402101,411285,525112,527999,540904,615586,627021,699059,718939,731636,773088,819519,842128,843287,860672,862174,874994,890189,897673,934713,955254}) = 37683