Week 3
Monday
Problem
Solution
Tuesday
Problem
Solution
Wednesday
Problem
Solution
Thursday
Problem
Solution
Last updated
Last updated
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int[] copy = candies.clone();
// Find maximum
Arrays.sort(candies);
int max = candies[candies.length - 1];
// Iterate through the list
List<Boolean> list = new ArrayList<>();
for (int i = 0; i < candies.length; i++) {
if (copy[i] + extraCandies >= max) {
list.add(true);
} else {
list.add(false);
}
}
return list;
}
}class Solution {
public String mergeAlternately(String word1, String word2) {
int pt1 = 0;
int pt2 = 0;
boolean dir = true;
int word1Len = word1.length();
int word2Len = word2.length();
StringBuilder res = new StringBuilder();
while (pt1 < word1Len && pt2 < word2Len) {
if (dir) {
res.append(word1.charAt(pt1));
pt1++;
} else {
res.append(word2.charAt(pt2));
pt2++;
}
dir = !dir;
}
// word 1 not ending
while (pt1 < word1Len) {
res.append(word1.charAt(pt1));
pt1++;
}
// word 2 not ending
while (pt2 < word2Len) {
res.append(word2.charAt(pt2));
pt2++;
}
return res.toString();
}
}class Solution {
public int largestAltitude(int[] gain) {
int cur = 0;
int max = 0;
for (int g : gain) {
cur += g;
max = Math.max(cur, max);
}
return max;
}
}