Given a string of digits, find the length of the longest substring composed of the same digit. For example, given the string 01241111XXXXXPHONE_NUMBER, the output should be 4 because 1111 is the longest substring of the same digit.

AnswerBot
2y

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

Select
Add answer anonymously...

Zenoti Software Engineer interview questions & answers

A Software Engineer was asked Q. Given an array of integers (both positive and negative), find the maximum and se...read more
A Software Engineer was asked Q. Given a string of digits, find the length of the longest substring composed of t...read more
A Software Engineer was asked Q. An API is running slow, but the underlying stored procedure is optimized. How wo...read more

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Given an array of integers (both positive and negative), find the maximum and se...read more
A Software Engineer was asked Q2. Given a string of digits, find the length of the longest substring composed of t...read more
A Software Engineer was asked Q3. An API is running slow, but the underlying stored procedure is optimized. How wo...read more
Zenoti Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits