
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum Power of Jump Required to Reach the End of String in C++
In this tutorial, we will be discussing a program to find maximum power of jump required to reach the end of string.
For this we will be provided with a string of 0s and 1s. Our task is to find the maximum jump required to move from front to end of string given you can move to the same element as current one.
Example
#include<bits/stdc++.h> using namespace std; //finding maximum power jump int powerOfJump(string s) { int count = 1; int max_so_far = INT_MIN; char ch = s[s.length() - 1]; for (int i = 0; i < s.length(); i++) { if (s[i] == ch) { if (count > max_so_far) { max_so_far = count; } count = 1; } else count++; } return max_so_far; } int main(){ string st = "1010101"; cout<<powerOfJump(st); }
Output
2
Advertisements