Reverse ArrayList Between 2 Given Indexes

Given an ArrayList and we need to reverse list from given startIndex to endIndex. example – List – [1,2,3,4], startIndex = 1, endIndex = 3 result = [1,4,3,2] List – [1,2,3,4,5], startIndex = 1, endIndex = 4 result = [1,5,4,3,2] Approach 1 – This approach starts swapping elements from startIndex and endIndex until startIndex is greater…

Read more...

HashMap in JAVA

Consider a scenario where we need to store data in the form of key value pairs. Which data structure will we use? Well, The obvious answer which comes in our mind is Map. HashMap is Hash table based implementation of the Map interface which stores data in the form of key value pairs. This class provides…

Read more...

SPOJ: PT07Y – Is it a tree

PT07Y – Is it a tree #dfs   You are given an unweighted, undirected graph. Write a program to check if it’s a tree topology. Input The first line of the input file contains two integers N and M — number of nodes and number of edges in the graph (0 < N <= 10000,…

Read more...

Convert int to String and String to int

This is one of the most occurred scenario where we need to convert a Integer to String or a String to Integer. We can attain that by using methods of wrapper classes. Here we are discussing about Integer -> String or String ->Integer. String to int To convert String to Integer we can use parseInt()….

Read more...
Bitnami