Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 578 |

@rdakka | 530 |

@praveenbgp6 | 529 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

Given an array arr of non-negative integers of size N, 2 players are playing a game. In each move, a player chooses an element from either end of the array, and the size of the array shrinks by one. Both players take alternate chances and the game continues until the size of the array becomes 0. Every time a player chooses an array element the array value is added to the player's score. At the need player with maximum score wins.

You have to predict whether player 1 will win the game or not. Both players will play optimally.

**Example 1:**

Input: N = 3 arr[] = {2,6,3}Output:0Explanation: Initially, player 1 can choose between 2 and 3. If he chooses 3 (or 2), then player 2 can choose from 2 (or 3) and 6. If player 2 chooses 6, then player 1 will be left with 2 (or 3). So, final score of player 1 is 2 + 3 = 5, and player 2 is 6. Hence, player 1 will never be the winner and output is 0.

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **is1winner()** which takes the array arr[], its size N** **and returns true if player 1 is the winner and false otherwise.

The driver code itself prints 1 if returned value is true and 0 otherwise.

**Expected Time Complexity:** O(N*N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 <= N <= 1000

0<= arr[i] <= 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Player with max score

...