Added 10 solutions

This commit is contained in:
Rodney Shaghoulian
2017-09-11 09:32:17 -07:00
parent 1b2f98dd95
commit ba2c70755b
81 changed files with 517 additions and 74 deletions
@@ -0,0 +1,42 @@
// Author: Rodney Shaghoulian
// Github: github.com/rshaghoulian
// HackerRank: hackerrank.com/rshaghoulian
import java.util.Scanner;
import java.util.Arrays;
// Time Complexity: O(n)
// Space Complexity: O(n) to save the input.
// You can reduce the space complexity to O(1) by omitting the array and
// working with the input directly, but it will make the code less modular
public class Solution {
static int cakeCandles(int[] candles) {
int tallest = 0;
int count = 0;
for (int candle : candles) {
if (candle > tallest) {
tallest = candle;
count = 1;
} else if (tallest == candle) {
count++;
}
}
return count;
}
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] candles = new int[n];
for (int i = 0; i < n; i++) {
candles[i] = scan.nextInt();
}
scan.close();
/* Get num candles blown out */
int result = cakeCandles(candles);
System.out.println(result);
}
}