Menu
Question Index
...


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   f
d   c   d   g
b   d   e   h
d   c   a   i 
  1    2    .    .
  .    3    4    .
  .    .    5    .
  .    .    .    .
o   a   p   l   l   z
z   b   c   k   m   n
g   e   d   k   p   s
w   f   g   e   n   m
l   h   f   z   f   q
q   i   g   y   z   g
  .    1    .    .    .    .
  .    2    3    .    .    .
  .    5    4    .    .    .
  .    6    7    .    .    .
  .    .    .    .    .    .
  .    .    .    .    .    . 
g  f  e
h  a  d
i  b  c
  7    6    5
  8    1    4
  9    2    3
z  a  y
g  b  k
h  c  s
g  d  t
  .    1    .
  .    2    .
  .    3    .
  .    4    .
z  w  v
m  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;
}
}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App