Skip to content

Instantly share code, notes, and snippets.

View dpkdns's full-sized avatar
🎯
One Thing At A Time

Deepak Tripathi dpkdns

🎯
One Thing At A Time
View GitHub Profile
@dpkdns
dpkdns / AliceAndCandy.java
Created May 24, 2018 19:45
Alice And His Candy - HackerEarth - Oyo Rooms
import java.util.Scanner;
class AliceAndCandy {
public static void main(String args[]) throws Exception {
Scanner scan = new Scanner(System.in);
int length = scan.nextInt();
int[] children = new int[length];
int[] candies = new int[length];
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
class FCTRLFactorial {
/**
* Count Trailing 0s or 5s in n!
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class IsItATree {
static int roots[];
public static void main(String[] args) throws IOException {
@dpkdns
dpkdns / ReverseListExample.java
Last active April 13, 2017 20:40
Test Reversing List between 2 indexes
import java.util.*;
public class ReverseListExample {
public static void main (String[] args) throws java.lang.Exception
{
List<Integer> list = new ArrayList<Integer>(Arrays.asList(2,5,4,3,1));
System.out.println("Original List - " + list);
spliceAndReverse(list, 1, 4);
System.out.println("Modified List - " + list);
System.out.println("Modified List using spliceAndReverseUsingSubList - " + spliceAndReverseUsingSubList(list, 0, 4));
@dpkdns
dpkdns / ReverseListUsingCollection.java
Last active April 13, 2017 20:34
Reverse List between 2 indexes using collection
static <E> List<E> spliceAndReverseUsingSubList(List<E> list, int startIndex, int endIndex){
List<E> subList = list.subList(startIndex, endIndex+1);
Collections.reverse(subList);
List<E> resultList = new ArrayList<>(list.subList(0, startIndex));
resultList.addAll(subList);
if(list.size() != endIndex+1){
resultList.addAll(list.subList(endIndex+1, list.size()));
}
return resultList;
}
@dpkdns
dpkdns / ReverseList.java
Created April 13, 2017 16:42
Reverses ArrayList between two indexes
static <E> List<E> spliceAndReverse(List<E> list, int startIndex, int endIndex){
while(startIndex < endIndex){
E e = list.get(startIndex);
list.set(startIndex, list.get(endIndex));
list.set(endIndex, e);
startIndex++;
endIndex--;
}
return list;
}
@dpkdns
dpkdns / HashMapExample.java
Last active April 11, 2017 21:09
Use of Basic Methods of HashMap
import java.util.HashMap;
/**
* @author Deepak Tripathi
* <br><br>
* Example code to explain methods of HashMap.
* @see <a href="http://blog.deepaktripathi.in/java/hashmap-in-java/">Deepak's Blog for more details</a>
*
*/