Blog Archives
1 2

01: String parsing & date formatting – complete the given code

Q. Complete the method “changeDateFormat(String paragraph)” which takes a string input containing dates in mm/dd/yyyy format and converts them to “dd/mm/yyyy” format. For example, “My birthday is on 04/25/1980” becomes “My birthday is on 25/04/1980

A. Here is the solution.

Read more ...


02: Working with Java Collections – Complete the given code

Q. Complete the method “canAttendAll(Collection seminars)” which takes a collection of seminar objects with start and end timestamps, and the method should determine if there is an overlap in seminars events. In other words, if you can attend all the seminars.

Read more ...


03: Tree navigation – is a BST Tree?

Q. Complete the method “isValidBST(Node root)” which takes a “Tree node” as an input to evaluate if the input is a valid BST (i.e. Binary Search Tree)?

Read more ...


04: Are Anagrams – Complete the given code

Q. Complete the “areAnagrams(String a, String b)” method so that it returns if two given input strings are anagram or not?

A. An anagram is a word formed from another by rearranging its letters. For example, “pat” & “tap”. Key steps 1) Convert both inputs to char arrays. 2)…

Read more ...


05: Is a palindrome – complete the given code

Q. Complete the method “isPalindrome(String str) ” which takes a “string” as an input to evaluate if the input is a palindrome?

A. A palindrome is a word, phrase, verse, or sentence that reads the same backward or forward. It should be case insensitive and ignore any no alpha…

Read more ...


06: Change Dir Path – String parsing & working with collections

Q. Complete the method ” public DirPath cd(String newPath)” which applies the following rules: /   : starting with “/” means root directory, else next directory path. ../ : means go up one directory.

Output should be: /a/b/c/x/y/z A. Key Steps 1) If the cd newPath starts with “/”, then…

Read more ...


07: Index of long consecutive characters in a string – flow control

Q. Complete the method “int startIndexOfLongestRun(String input)” that returns the start index of a character that has the longest consecutive count.

A. A map cannot be used here as the same character can repeated. For example, “a” is repeated. Also, the task is to find the starting index of…

Read more ...


08: Jumping Frog problem in Java – Complete the given code

Q. Complete the method “int numberOfWays(int n)” where n is the distance to cover and the method should return the number of possible combinations if a frog can jump 1 or 2 steps at a time.

The distance of 3 will have the following 3 combinations: 1) [1, 1,…

Read more ...


09: Find all permutations of a given string – best example to understand recursion

Q. Complete the method “Set getAllCombinations(String input) ” where input is any string and the method should return all possible combinations of a given string.

For example: “abc” will have a permutation of 3! (i.e. 3 factorial) = 3 * 2 * 1 = 6 combinations of: result=[bca, acb,…

Read more ...


10: Find all permutations of a given string – Iteration in Java

Q. Complete the method “Set getAllCombinations(String input) ” where input is any string and the method should return all possible combinations of a given string.

For example: “abc” will have a permutation of 3! (i.e. 3 factorial) = 3 * 2 * 1 = 6 combinations of: result=[bca, acb,…

Read more ...


1 2

500+ Enterprise & Core Java programmer & architect Q&As

Java & Big Data Tutorials

Top