Author Archives: Venkateswarlu Chennareddy
Difference between JDK, JRE and JVM
JVM JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms. JVM, JRE and JDK are platform dependent … Continue reading
Kth largest number in BST
Given a Binary Search Tree (BST) and a positive integer k, find the k’th largest element in the Binary Search Tree. For example, in the following BST, if k = 3, then output should be 14, and if k = … Continue reading
Popular Java interview questions 2
Difference between Array and ArrayList in Java Array ArrayList Resizable No Yes Primitives Yes No Iterating values for, for each Iterator , for each Length length variable size method Performance Fast Slow in comparision Multidimensional Yes No Add Elements Assignment … Continue reading
Popular Java Interview Questions
1. Which two method you need to implement for key Object in HashMap ? In order to use any object as Key in HashMap, it must implements equals and hashcode methods in Java. 2. What is immutable object? Can you … Continue reading
Difference between “implements Runnable” and “extends Thread” in Java
1. Inheritance Option: The limitation with “extends Thread” approach is that if you extend Thread, you can not extend anything else . Java does not support multiple inheritance. In reality , you do not need Thread class behavior , … Continue reading
Difference between wait and sleep methods
Difference between Sleep and Wait method in Java 1. Class belongs : The wait() method belongs to java.lang.Object class, thus can be called on any Object. The sleep() method belongs to java.lang.Thread class, thus can be called on Threads. 2. Context … Continue reading
Coin Change
Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The … Continue reading
Majority Element
Majority Element: A majority element in an array A[] of size n is an element that appears more than n/2 times (and hence there is at most one such element). Write a function which takes an array and emits the … Continue reading
Find duplicates in O(n) time and O(1) extra space
Given an array of n elements which contains elements from 0 to n-1, with any of these numbers appearing any number of times. Find these repeating numbers in O(n) and using only constant memory space. For example, let n be … Continue reading
Given an array arr[], find the maximum j – i such that arr[j] > arr[i]
Given an array arr[], find the maximum j – i such that arr[j] > arr[i]. Examples: Input: {34, 8, 10, 3, 2, 80, 30, 33, 1} Output: 6 (j = 7, i = 1) Input: {9, 2, 3, 4, 5, … Continue reading