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
| def twoSum(self, nums: List[int], target: int) -> List[int]: | |
| seen = {} | |
| for index, num in enumerate(nums): | |
| other = target - num | |
| if other in seen: | |
| return[seen[other],index] | |
| else: | |
| seen[num] = index |
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
| def multiples(n): | |
| sum = 0 | |
| for i in range(n): | |
| if(i%3==0) or (i%5==0): | |
| sum += i | |
| return sum | |
| print(multiples(1000)) |
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
| #include <iostream> | |
| #include <iomanip> | |
| #include <limits> | |
| using namespace std; | |
| int main() { | |
| int i = 4; | |
| double d = 4.0; | |
| string s = "HackerRank "; |
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
| i2 = int(input()) | |
| d2 = float(input()) | |
| s2 = input() | |
| print(i + i2) | |
| print(d + d2) | |
| print(s + s2) |
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
| // Declare second integer, double, and String variables. | |
| // Read and save an integer, double, and String to your variables. | |
| var i2 = +(readLine()); | |
| var d2 = +(readLine()); | |
| var s2 = readLine(); | |
| // Print the sum of both integer variables on a new line. | |
| console.log(i + i2); | |
| // Print the sum of the double variables on a new line. |
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
| /** | |
| * Calculate the area of a rectangle. | |
| * | |
| * length: The length of the rectangle. | |
| * width: The width of the rectangle. | |
| * | |
| * Return a number denoting the rectangle's area. | |
| **/ | |
| function getArea(length, width) { | |
| let area; |
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
| /* | |
| * Create the function factorial here | |
| * Recursion: To call itself is called recursion. | |
| */ | |
| function factorial(n) { | |
| if (n === 0) { | |
| return 1; | |
| } | |
| return n * factorial(n - 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
| function main() { | |
| // Write your code here. Read input using 'readLine()' and print output using 'console.log()'. | |
| let r = readLine(); | |
| const PI = Math.PI; | |
| // Print the area of the circle: | |
| console.log(PI * (r * r) ); | |
| // Print the perimeter of the circle: | |
| console.log(2 * PI * r); | |
| } |
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 getGrade(score) { | |
| let grade; | |
| // Write your code here | |
| if(score<=5) { | |
| grade="F"; | |
| }else if(score<=10) { | |
| grade='E'; | |
| }else if(score<=15) { | |
| grade='D' | |
| }else if(score<=20) { |
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 getLetter(s) { | |
| let letter; | |
| // Write your code here | |
| switch (true) { | |
| case 'aeiou'.includes(s[0]): | |
| letter = 'A'; | |
| break; | |
| case 'bcdfg'.includes(s[0]): | |
| letter = 'B'; | |
| break; |