- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- Count number of ways to jump to reach end in C++
- Find the minimum of maximum length of a jump required to reach the last island in exactly k jumps in Python
- Find minimum steps required to reach the end of a matrix in C++
- How to find the minimum number of jumps required to reach the end of the array using C#?
- Program to find minimum number of hops required to reach end position in Python
- C Program for Minimum number of jumps to reach the end
- C++ code to find minimum jump to reach home by frog
- Add a string to the end of the StringCollection in C#
- Count of lines required to write the given String in C++
- C++ program to find out number of changes required to get from one end to other end in a grid
- C# Program to remove the end part of a string
- Program to find number of given operations required to reach Target in Python
- Finding minimum number of required operations to reach n from m in JavaScript
- Find if it is possible to reach the end through given transitions in C++
- Program to find minimum number of buses required to reach final target in python

Advertisements