Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anushshukla/658cc4131d91796f2ac6698280b3a1a0 to your computer and use it in GitHub Desktop.

Select an option

Save anushshukla/658cc4131d91796f2ac6698280b3a1a0 to your computer and use it in GitHub Desktop.
Count family login pairs (AWS SDE Assessment Coding Challenge)
function countFamilyLoginsPairs(logins) {
// Write your code here
let familyLoginPairsCount = 0;
const cachedResults = {};
logins.map((login, currentLoginIndex) => {
const possibleLoginPairs = ['', ''];
cachedResults[login] = 0;
if (cachedResults[login]) {
cachedResults[login] += 1;
familyLoginPairsCount++;
}
[...login].map(loginLetter => {
const loginLetterCharCode = loginLetter.charCodeAt(0);
possibleLoginPairs[0] += String.fromCharCode(loginLetterCharCode === 122 ? 97 : loginLetterCharCode + 1);
possibleLoginPairs[1] += String.fromCharCode(loginLetterCharCode === 97 ? 122 : loginLetterCharCode - 1);
});
// console.log(login, possibleLoginPairs);
for(let nextLoginIndex = currentLoginIndex + 1; nextLoginIndex < logins.length; nextLoginIndex++) {
const nextLogin = logins[nextLoginIndex];
if (possibleLoginPairs.includes(nextLogin)) {
familyLoginPairsCount++;
cachedResults[login] += 1;
}
}
});
// console.log(logins, familyLoginPairsCount);
return familyLoginPairsCount;
}
countFamilyLoginsPairs(['ab', 'bc', 'zz', 'aa', 'bb', 'cc', 'cc', 'cc', 'aa']) // 8
class Solution {
public List<String> fizzBuzz(int n) {
List output = new ArrayList();
for (int i = 1; i <= n; i++) {
String print = i % 3 == 0 ? "Fizz" : "";
if (i % 5 == 0) {
output.add(print + "Buzz");
continue;
}
output.add(print.isEmpty() ? Integer.toString(i) : print);
}
return output;
}
}
const isDivisbleBy = (numerator: number, denominator: number): boolean =>
numerator % denominator === 0;
const fizzBuzz = (num: number): void => {
for (let n = 1; n <= num; n++) {
let print = n % 3 === 0 ? 'Fizz' : '';
if (n % 5 === 0) {
console.log(print + 'Buzz');
continue;
}
console.log(print || n);
}
}
@tsenior
Copy link
Copy Markdown

tsenior commented Jul 25, 2022

i got this question and got zero zil, can you do this in Java?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment