Longest tower

Longest tower

In human tower, people standing atop of one another’s shoulders, with constraints, a person on top of another must be lighter and and shorter of below person. Now you have weight and height of each person, compute largest possible tower from given persons details.

Solution:

  • A simple solution is based on longest contiguous subsequence
Algorithm:
  • First sort the given persons based on height and then weight
  • Iterate each one by one and create list of longest contiguous subsequence list till this index
  • Find longest list from all longest contiguous subsequence list

Latest Source Code:
Github: LongestTower.java


Output:

 Persons: [Person{h=65, w=100}, Person{h=70, w=150}, Person{h=56, w=90}, Person{h=75, w=190}, Person{h=60, w=95}, Person{h=68, w=110}]
Longest Tower: [Person{h=56, w=90}, Person{h=60, w=95}, Person{h=65, w=100}, Person{h=68, w=110}, Person{h=70, w=150}, Person{h=75, w=190}]

StackOverFlow

Author: Hrishikesh Mishra