This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
* | |
*/ |
NewerOlder