Skip to content

Instantly share code, notes, and snippets.

@bhaveshmunot1
Created June 3, 2020 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhaveshmunot1/28236e7e2a8ae51a9ee55d435b1d0b65 to your computer and use it in GitHub Desktop.
Save bhaveshmunot1/28236e7e2a8ae51a9ee55d435b1d0b65 to your computer and use it in GitHub Desktop.
Find maximum number in an array using recursion.
int max_in_array(vector<int> nums, int start_index, int end_index) {
if (start_index == end_index) {
return nums[start_index];
}
int maximum = max_in_array(nums, start_index+1, end_index);
return max(nums[start_index], maximum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment