Find the length of longest substring composed of same digit, within a string of digits: (was asked to complete within 10 mins) E.g. 01241XXXXX901111 Output: 4 Explanation: "1111" is the longest substring

AnswerBot
1y

Find the length of longest substring composed of same digit within a string of digits.

  • Iterate through the string and keep track of the current digit and its count

  • Update the maximum count whenever a ne...read more

MOHAMMAD SHANAVAZ
1y

Code in CPP:

#include <bits/stdc++.h>

using namespace std;

int main()

{

//input

string s="01241XXXXX901111";

//storing integer values in the vector

vector<int>ans;

for(int i=0;i<s.size();i++)

{

if(s[i]-...read more

Rakesh Modi
1y

#python

arr=input()

c=1

char=arr[0]

ans=1

h={}

if len(arr)==0:

print(0)

else:

for i in range(1,len(arr)):

if arr[i].isdigit():

if char==arr[i]:

c+=1

ans=max(ans,c)

else:

c=1

char=arr[i]

print(ans)

#input 0124...read more

Shylesh Arepelly
1y

def find_longest_same_digit_substring(s):

if not s:

return 0

max_length = 1 # Initialize with 1 to account for the single character substring

current_length = 1

current_digit = s[0]

for i in range(1, ...read more

Add answer anonymously...
Zenoti Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter