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)]

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