1 2 3

Generating random numbers in Java

Q1. Can you write Java code to generate random numbers between a given range? A1. E.g. 0 and 9 or 5 to 35, and so on.

The “nextInt()” method works from “0” onwards. So, “rand.nextInt(9)” will …

Huffman coding in Java

This is a very decent coding exercise to sharpen your coding skills. Nicely explained with diagrams and complete code. Q1. What is Huffman coding? A1. Huffman coding is a compression technique used to reduce the number of bits needed to send or store a message. For example, if you have… …

Iteration Vs Recursion

Q1. Can you write a sample code that will count the number of “A”s in a given text “AAA rating“? Show both iterative and recursive approaches?
A1.

Iteration:

A for loop to traverse through each character of the String “AAA rating”, and a if condition to …

Java 8 String streams and finding the first non repeated character with functional programming

Q1.Find the first non repeated character in a given string input using Java 8 or later? A1.Extends Find the first non repeated character in a given string input with Java 8 functional programming.

Java coding practice problems – prime and powerful

There is no other way to pass the Java coding tests other than practicing. I have failed Java coding tests due to lack of practice. How often do you get work with tree and graph data structures? Ho often do you work with algorithms?

Java coding question on recursion and generics

Q. Can you write Java code to compute a collection of numbers supplied to it? The computation could be addition, subtraction, etc. Use recursion to compute the numbers. Here are some requirements to take into considerations. 1. It should be flexible enough to convert from Recursion to iteration if required…. …

Palindrome

Q1. Can you write a function to determine if a given string input is a palindrome? A palindrome is a word or sentence that reads the same forward as it does backward. For example, the terms “racecar”, “dad”, “madam” and the name “Hannah”. The longest palindromic substring of “bananas” is… …

Reverse a given String

Q1. Can you write a method that reverses a given String? A1. Can be done a number of different ways. Best Practice: Using the Proven Java API

Reverse Polish Notation (RPN)

Q1. Can you explain Reverse Polish Notation (RPN)? A1. You have already heard about the following from your elementary schooling: “Please Excuse My Dear Aunt Sally” (meaning Parentheses, Exponentiation (roots and powers), Multiplication, Division, Addition, and Subtraction BODMAS, tells us to attend to Brackets, Of, Division, Multiplication, Addition, and Subtraction… …

Sorting a list of numbers by frequencies in Java using a BST tree

This extends Sorting a list of numbers by frequencies in Java using a map to use a BST instead of a Map.

PROBLEM to solve: Sort a list of numbers by frequency of their occurrences. For example

INPUT: [ 5, 3, 7, 7, 7, 5, 4, 8 ]

OUTPUT: [7, …

1 2 3
Top 