Thanks to visit codestin.com
Credit goes to github.com

Skip to content

lpenap/hackerrank-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Collection of HackerRank problem solutions.

Personal collection of solutions to HackerRank problems using Java.

You will find project files for Eclipse and an easy method to switch from local file inputs to hackerrank.com System.in inputs.

Also, you'll find: URL to problem statement, order of the function (O notation) and solution approach on each source file.

Switching from local input to hackerrank

Use the following method to switch between inputs:

	public BufferedReader inputFromHackerrank(boolean fromHackerrank) {
		String DIR_SEP = "/";
		if (fromHackerrank) {
			return new BufferedReader(new InputStreamReader(System.in));
		} else {
			return new BufferedReader(new InputStreamReader(
				getClass().getResourceAsStream(DIR_SEP +
					getClass().getPackage().getName().replaceAll(
						"\\.", DIR_SEP) + DIR_SEP + "input.txt")));
		}
	}

Passing true to the above method will use input from hackerrank. Passing false will make use of the input.txt file on each problem package (Adjust your folder separator string accordingly). For example:

	public static void main(String[] args) {
		BufferedReader br = inputFromHackerrank(false);
		Scanner in = new Scanner(br);
		String a = in.next();
		String b = in.next();
		System.out.println(numberNeeded(a, b));
	}
	public static BufferedReader inputFromHackerrank(boolean fromHackerrank) {
		String DIR_SEP = "/";
		if (fromHackerrank) {
			return new BufferedReader(new InputStreamReader(System.in));
		} else {
			return new BufferedReader(new InputStreamReader(
				getClass().getResourceAsStream(DIR_SEP +
					getClass().getPackage().getName().replaceAll(
						"\\.", DIR_SEP) + DIR_SEP + "input.txt")));
		}
	}

List of solved problems

See the list of solved problems.

About

Personal collection of HackerRank solutions in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages