info@meritcampus.com    +91-85006-22255
...

Write a program to print the longest chain of ascending characters from the given character matrix.
Note: The longest path is represented with series of characters (a, b, c,...) as shown in the requirements. When two chains are of equal size the direction preference is Right, Left, Down and Up.

Input (Two Dimensional matrix) Printed Output
`a   b   f   fd   c   d   gb   d   e   hd   c   a   i ` `  1    2    .    .  .    3    4    .  .    .    5    .  .    .    .    .`
`o   a   p   l   l   zz   b   c   k   m   ng   e   d   k   p   sw   f   g   e   n   ml   h   f   z   f   qq   i   g   y   z   g` `  .    1    .    .    .    .  .    2    3    .    .    .  .    5    4    .    .    .  .    6    7    .    .    .  .    .    .    .    .    .  .    .    .    .    .    . `
`g  f  eh  a  di  b  c` `  7    6    5  8    1    4  9    2    3`
`z  a  yg  b  kh  c  sg  d  t` `  .    1    .  .    2    .  .    3    .  .    4    .`
`z  w  vm  o  u` `  .    3    2  .    .    1`

``` class PrintLongestChainOfAscendingCharacters {    public static void main(String s[])    {        char[][] input = {{'a', 'b', 'f', 'f'}, {'d', 'c', 'd', 'g'}, {'b', 'd', 'e', 'h'}, {'d', 'c', 'a', 'i'}};        printLongestChainOfCharacters(input);    } public static void printLongestChainOfCharacters(char[][] input) { //Write code here to print the longest chain formed by ascending characters } //If required, write any additional methods here } class Position { int rowPosition; int columnPosition; public Position(int rowPosition, int columnPosition) { this.rowPosition = rowPosition; this.columnPosition = columnPosition; } @Override public boolean equals(Object obj) { return rowPosition == ((Position) obj).rowPosition && columnPosition == ((Position) obj).columnPosition; } @Override public String toString() { return rowPosition + "," + columnPosition; } } ```

Topic: Java ArrayList

0
Wrong
Score more than 2 points