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
// Complete the countingValleys function below. | |
static int countingValleys(int n, String s) { | |
int noOfValleys = 0; | |
int currentLevel = 0; | |
for(char c: s.toCharArray()){ | |
if(c == 'U') ++currentLevel; | |
if(c == 'D') --currentLevel; | |
if(currentLevel == 0 && c == 'U') ++noOfValleys; | |
} | |
return noOfValleys; |
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 int sockMerchant(int n, int[] arr) { | |
Set<Integer> colors = new HashSet<>(); | |
int pairs = 0; | |
if(n == arr.length){ | |
for (int i = 0; i < n; i++) { | |
if (colors.remove(arr[i])) { | |
pairs++; | |
} else { | |
colors.add(arr[i]); | |
} |
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
var input = `1 | |
30 8 10 15 16 18 30`; | |
function start(input){ | |
if(input !== ""){ | |
var inputSplittedByLine = input.split("\n"); | |
var noOfStatements = inputSplittedByLine[0]; | |
if(noOfStatements == inputSplittedByLine.length-1){ | |
for(var i =1; i < inputSplittedByLine.length; i++){ | |
var currentStatementSplitted = inputSplittedByLine[i].split(" "); |
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
var input = `2 | |
5 16 | |
9 7 2 16 4 | |
7 98 | |
1 22 57 47 34 18 66`; | |
function searchNumber(digit, input){ | |
var output = -1; | |
for(var i=0; i <input.length; i++){ | |
if(digit == input[i]){ |
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
// you can also use imports, for example: | |
import java.util.*; | |
// you can write to stdout for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int len = A.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.util.*; | |
// you can write to stdout for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int length = A.length; | |
int min = 0; |
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
// you can also use imports, for example: | |
import java.util.*; | |
// you can write to stdout for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
class Solution { | |
public int solution(int N) { | |
// write your code in Java SE 8 | |
int count = 0; |
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.*; | |
class IsAnagramPalindrome{ | |
public static boolean isAnagramOfPalindrome(String s){ | |
if(s.length() == 0){ | |
return false; | |
} | |
if(s.length() == 1){ |
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
class FizzBuzz { | |
public static void solution(int N) { | |
// write your code in Java SE 8 | |
int count = 0; | |
int contCount = 0; | |
for(int i = 1; i<=N;i++){ | |
if((i % 3 == 0) && (i % 5 == 0) && (i % 7 == 0)){ | |
System.out.println("FizzBuzzWoof"); |
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.Arrays; | |
public class BinarySearchIndex { | |
public static int binarySearchIndex(int[] arr, int item) { | |
int length = arr.length; | |
int hi = length-1; | |
int lo = 0; |
NewerOlder