Example 1: input1: 5 input2: (-2, 3, -1, -4, -2) Output: 8 Explanation: Since Fred can flip consecutive cards only once, he chooses to flip the last three which results in the maximum sum (-2 +3 +1 +...


Example 1:<br>input1: 5<br>input2: (-2, 3, -1, -4, -2)<br>Output: 8<br>Explanation:<br>Since Fred can flip consecutive cards only once, he chooses to flip the last three<br>which results in the maximum sum (-2 +3 +1 + 4 +2), i.e., 8.<br>Therefore, 8 is returned as the output.<br>Example 2:<br>put1: 5<br>input2: (-1, 2, 3, 4, -5}<br>Output: 13<br>Explanation:<br>Since Fred can flip consecutive cards only once, he chooses to flip the last card,<br>results in the maximum sum (-1 +2 + 3 +4 +5), i.e., 13.<br>Therefore, 13 is returned as the output.<br>

Extracted text: Example 1: input1: 5 input2: (-2, 3, -1, -4, -2) Output: 8 Explanation: Since Fred can flip consecutive cards only once, he chooses to flip the last three which results in the maximum sum (-2 +3 +1 + 4 +2), i.e., 8. Therefore, 8 is returned as the output. Example 2: put1: 5 input2: (-1, 2, 3, 4, -5} Output: 13 Explanation: Since Fred can flip consecutive cards only once, he chooses to flip the last card, results in the maximum sum (-1 +2 + 3 +4 +5), i.e., 13. Therefore, 13 is returned as the output.
How to attempt?<br>Question:<br>The Card Game<br>One day, Fred and his N friends were playing a card game in which each player throws a<br>card with a number written on it. The cards are such that a number X is written on front of<br>the card, and fthe negative of that number is written on the back side of the card. This<br>game has the following rules: -<br>Each of the N players is asked to throw a card. After all the N cards are thrown, Fred has<br>to flip one or more cards in conseculive order, only once.<br>Your lask is to help Fred flip the cards in such a way that the sum of the numbers, on<br>front face of the cards, is the maximym.<br>Input Specification:<br>Input1: An integer N denoting the number of cards (1 <= N <= 500)<br>input2: An integer array containingN integers, where the ith integer<br>denotes the value on the front of the card (-1000<= input2[Ű<= 1000)<br>Output Specification:<br>Return the maximum sum of the numbers, on the front of the cards<br>Example 1:<br>

Extracted text: How to attempt? Question: The Card Game One day, Fred and his N friends were playing a card game in which each player throws a card with a number written on it. The cards are such that a number X is written on front of the card, and fthe negative of that number is written on the back side of the card. This game has the following rules: - Each of the N players is asked to throw a card. After all the N cards are thrown, Fred has to flip one or more cards in conseculive order, only once. Your lask is to help Fred flip the cards in such a way that the sum of the numbers, on front face of the cards, is the maximym. Input Specification: Input1: An integer N denoting the number of cards (1 <= n=""><= 500)="" input2:="" an="" integer="" array="" containingn="" integers,="" where="" the="" ith="" integer="" denotes="" the="" value="" on="" the="" front="" of="" the="" card=""><=><= 1000)="" output="" specification:="" return="" the="" maximum="" sum="" of="" the="" numbers,="" on="" the="" front="" of="" the="" cards="" example="">

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here