Last active
July 26, 2022 04:09
-
-
Save anushshukla/658cc4131d91796f2ac6698280b3a1a0 to your computer and use it in GitHub Desktop.
Count family login pairs (AWS SDE Assessment Coding Challenge)
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
| 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 |
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 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; | |
| } | |
| } |
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
| 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); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i got this question and got zero zil, can you do this in Java?