Java code to find index of longest repeated letters in a string

Here’s the Java code to find index of the longest consecutive sequence of repeated letters in a string. If there is more than one run with the same length, the index of the first one is returned.
For example, if the string is(“bbbccffffiiiffff”), the program should return 5 as the longest sequence is ffff and it first appears on index 5.

Continue reading

Java code to determine the validity of a binary search tree

Write a code to determine the validity of a binary search tree (BST). A binary search tree is rooted binary tree, whose internal nodes each store a key and each have two distinguished sub-trees, commonly denoted left and right. The key in each node must be greater than all keys stored in the left sub-tree, and smaller than all keys in right sub-tree. Below is an example of a BST:

Binary_search_tree

Continue reading