Redirecting to
NADOS
 Largest Square Submatrix With All 1's
 Print All Paths With Minimum Jumps
 Print All Paths With Minimum Cost
 Print All Paths With Maximum Gold
 Print All Paths With Target Sum Subset
 Print All Results In 01 Knapsack
 2 Key Keyboard
 4 Key Keyboard
 Longest Increasing Subsequence
 Print All Longest Increasing Subsequences
 Maximum Sum Increasing Subsequence
 Longest Bitonic Subsequence
 Maximum Nonoverlapping Bridges
 Russian Doll Envelopes
 Min Squares
 Catalan Number
 Number Of Bsts
 Count Of Valleys And Mountains
 Count Brackets
 Circle And Chords
 Number Of Ways Of Triangulation
 Catalan Numbers Variation
 Matrix Chain Multiplication
 Burst Balloons
 Minimum Score Of Triangulation
 Boolean Parenthesization
 Optimal Binary Search Tree
 Rod Cutting
 Minimum Palindromic Cut
 Longest Common Subsequence
 Longest Palindromic Subsequences
 Count Palindromic Subsequences
 Count Palindromic Substrings
 Longest Palindromic Substring
 Count Distinct Subsequences
 Count Of Distinct Palindromic Subsequences
 Wildcard Pattern Matching
 Regular Expression Matching
 Longest Common Substring
 Longest Repeating Subsequence
 Edit Distance
 Scramble String
 Minimum Ascii Delete Sum For Two Strings
 Minimum Cost To Make Two Strings Identical
 Kadane's Algorithm
 K Concatenation
 Maximum Sum Subarray With At Least K Elements
 Egg Drop
 Optimal Strategy For A Game
 Cherry Pickup
 Probability Of Knight In The Chessboard
 Highway Billboard
 Distinct Transformations
 Numeric Keypad
 Maximum Difference Of Zeros And Ones In Binary String
 Maximum Sum Of Two Nonoverlapping Subarrays
 Maximum Sum Of Three Nonoverlapping Subarrays
 Maximum Sum Of M Nonoverlapping Subarrays
 Arithmetic Slices 1
 Arithmetic Slices 2
 Word Break
 Temple Offerings
 Minimum Insertions To Make Palindrome
 Ugly Number
 Super Ugly Number
 Find Water In Glass
 Frog Jump
 Interleaving Of Two Strings
 Maximum Length Of Repeated Subarray
 Distinct Echo Substrings
 Minimum Cost To Cut A Stick
 Delete And Earn
 Number Of Good Ways To Split A String
 Minimum Cost For Tickets
 Minimum Ascii Delete Sum For Two Strings
 Maximum Alternating Subsequence Sum
 Stone Game
 Largest Multiple Of Three
 Longest Increasing Subsequence
 Maximum Sum Increasing Subsequence
 Longest Bitonic Subsequence
 Temple Offerings
 Count Palindromic Substrings
 Minimum Score Of Triangulation
 Catalan Numbers Variation
 Print All Paths With Minimum Jumps
 Maximum Sum Of Two Nonoverlapping Subarrays
 Arithmetic Slices  2
 Longest Common Substring
 Count Brackets
 Minimum Cost To Make Two Strings Identical
 Number of Ways of Triangulation
 Russian Doll Envelopes
 Maximum Non  Overlapping Bridges
 Kadanes Algorithm
 Count Palindromic Subsequence
 Circle and Chords
 Optimal Strategy For a Game
 Maximum Sum of 3 NonOverlapping Subarrays
 Print All Paths With Target Sum Subset
 Regular Expression Matching
 Number of BSTs
 Count of Valleys and Mountains
 Longest Palindromic Substrings
 Distinct Transformations
 Find Water In Glass
 Arithmetic Slices  1
 Largest Square Sub Matrix with all 1s
 Maximum Length of Repeated Subarray
 All Repeating Except One
 Min Squares
 Numeric Keypad
 Word Break2
 Minimum Palindromic Cuts
 Rod Cutting
 Burst Balloons
 Maximum Sum Of M Nonoverlapping Subarrays
 Print All Longest Increasing Subsequences
 Longest Common Subsequence
 Count Distinct Subsequences
 Print All Paths With Minimum Counts
 Print all Paths with Maximum Gold
 Print All Results In 01 Knapsack
 Wildcard Pattern Matching
 Catalan Numbers
 Boolean Parenthesization
 Optimal Binary Search Tree
 Longest Repeating Subsequence
 Minimum Ascii Delete Sum for Two Strings
 Edit Distance
 K Concatenation
 Maximum Sum Subarray With At Least K Elements
 Egg Drop
 Scramble String
 Highway Billboard
 Minimum Insertions To Make Palindrome
 Ugly Number
 Super Ugly Number
 Frog Jump
 Interleaving of two strings
Cherry Pickup
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.
1. You are given a number N, which represents the rows and columns of a 2D matrix.Input Format
2. Matrix contains only three values 
a. Cell is empty.
b. Cell contains a cherry.
c. Cell contains a thorn and you can not pass through this cell.
3. You have to find the maximum number of cherries that you can collect following these rules :
a. You have to start from (0,0) and travel till (N1,N1) by moving right or down,
one step at a time.
b. After reaching (N1,N1), you have to come back to (0,0) by moving left or up,
one step at a time.
Note > If there is no valid path between the topleft cell and bottomright cell, then no cherries can be collected.
A number NOutput Format
arr1
arr2... (N*N numbers).
Check the sample output and question video.Question Video Constraints
1 <= N <= 50Sample Input
Cells can have only three values 0,1 and 1.
3Sample Output
0
1
1
1
0
1
1
1
1
5

Asked in Companies

Related Topics
Your profile is incomplete!
Please click here to complete your profile to continue submitting questions.
Video Solution
Code Solution
{ }
Editor Settings
Font Size
Key Binding
Keyboard Shortcut
 fold AltLCtrlF1
 unfold AltShiftLCtrlShiftF1
 Gotoend CtrlEnd
 Gotostart CtrlHome
 Movelinesup AltUp
 Movelinesdown AltDown
 Undo CtrlZ
 Redo CtrlShiftZCtrlY
 Replace CtrlH
 Togglecomment Ctrl/
 ToggleBlockComment CtrlShift/
 Removeline CtrlD
{ }
Run
Editor Settings
Font Size
Key Binding
Keyboard Shortcut
 fold AltLCtrlF1
 unfold AltShiftLCtrlShiftF1
 Gotoend CtrlEnd
 Gotostart CtrlHome
 Movelinesup AltUp
 Movelinesdown AltDown
 Undo CtrlZ
 Redo CtrlShiftZCtrlY
 Replace CtrlH
 Togglecomment Ctrl/
 ToggleBlockComment CtrlShift/
 Removeline CtrlD