Consecutive Characters Problem Statement

Given a matrix of lowercase characters with dimensions 'N' rows and 'M' columns, and a string 'STR', your goal is to find the longest consecutive character path length for each character in 'STR'. Characters in the path should be consecutive in alphabetical order, and movement is allowed in all 8 adjacent directions from a cell.

Example:

Input:
N = 2, M = 2, STR = "a"
Matrix:
a b
e d
Output:
[2]
Explanation:

The longest path starting with 'a' is [a, b]. Therefore, the length is 2.

Constraints:

  • 1 <= T <= 10
  • 1 <= M <= 300
  • 1 <= N <= 300
  • ‘a’ <= matrix[i][j], STR[i] <= ‘z’
  • 1 <= |STR| <= 26
  • Time Limit: 1 sec
Note:

You may move to the following positions from (x, y):
[(x+1, y), (x-1, y), (x, y+1), (x, y-1), (x+1, y+1), (x+1, y-1), (x-1, y+1), (x-1, y-1)]

AnswerBot
4mo

Find the longest consecutive character path length for each character in a matrix given a string.

  • Iterate through the matrix and for each character in the string, find the longest consecutive path in a...read more

Anonymous
1y
good
Help your peers!
Select
Add answer anonymously...
Info Edge Test 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