├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── Day0 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day1 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py └── Solution.swift ├── Day10 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day11 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day12 ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day13 ├── Solution.cpp ├── Solution.java └── Solution.py ├── Day14 ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day15 ├── Solution.c ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day16 ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day17 ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day18 ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day19 ├── Solution.cpp ├── Solution.java └── Solution.py ├── Day2 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py └── Solution.swift ├── Day20 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day21 ├── Solution.cpp ├── Solution.java └── Solution.swift ├── Day22 ├── Solution.c ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day23 ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day24 ├── Solution.c ├── Solution.cpp ├── Solution.java ├── Solution.py └── Solution.swift ├── Day25 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day26 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day27 ├── Solution.c ├── Solution.cpp ├── Solution.java ├── Solution.py └── TestCase_file.txt ├── Day28 ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day29 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day3 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day4 ├── Solution.cpp ├── Solution.java ├── Solution.py ├── Solution.rs ├── Solution.swift └── solution.go ├── Day5 ├── Solution.c ├── Solution.cpp ├── Solution.java ├── Solution.py ├── Solution.rs ├── Solution.swift └── solution.go ├── Day6 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day7 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py └── Solution.swift ├── Day8 ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── Day9 ├── Solution.c ├── Solution.cpp ├── Solution.go ├── Solution.java ├── Solution.py ├── Solution.rs └── Solution.swift ├── LICENSE.md └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | From opening a bug report to creating a pull request: every contribution is appreciated and welcome. 4 | 5 | ## Issues 6 | 7 | 8 | ### New Issue/Addition 9 | 10 | If you come across a **new** Issue or looking for adding new Solutions, you need to create an issue, Provide description for it and once it's reviewed it will be assigned to you and then you can start working on it. 11 | 12 | ### Existing Issue 13 | 14 | * To contribute to Existing issue you need to comment telling which question solution you want to work at a time. 15 | * You can work on **multiple** questions but make sure not to pick **max 4** question at a time. 16 | * Once reviewed it will be assigned to you then you can start working on it. 17 | 18 | 19 | ## Creating Pull Request 20 | 21 | * Make a fork of this repository. 22 | * Clone your forked repository to your local. 23 | * Create a new Branch from master branch. 24 | * If you are creating a new solution, please follow the pattern "Solution." 25 | * Make changes/addition to it and commit to your new branch. 26 | * Make sure to add proper commit message describing what all question solutions you added/fixed. for e.g 27 | * if new solution added for day 1 in python language: 28 | ``` 29 | Add: solution for [Day 1] in [Python] language 30 | ``` 31 | * if you made changes to existing solution of day 1 of python to make it run with python3, then: 32 | ``` 33 | Update: solution for [Day 1] in [Python] language to run with python v3. 34 | ``` 35 | * Create a PR to this Repository from your forked repository providing description of what you did. 36 | * Once Reviewed, It will be merged to the Repo. 37 | -------------------------------------------------------------------------------- /Day0/Solution.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | // Declare a variable named 'input_string' to hold our input. 3 | char input_string[105]; 4 | 5 | // Read a full line of input from stdin and save it to our variable, input_string. 6 | scanf("%[^\n]", input_string); 7 | 8 | // Print a string literal saying "Hello, World." to stdout using printf. 9 | printf("Hello, World.\n"); 10 | 11 | printf("%s", input_string); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Day0/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main() { 2 | // Declare a variable named 'input_string' to hold our input. 3 | string input_string; 4 | 5 | // Read a full line of input from stdin (cin) and save it to our variable, input_string. 6 | getline(cin, input_string); 7 | 8 | // Print a string literal saying "Hello, World." to stdout using cout. 9 | cout << "Hello, World." << endl; 10 | cout << input_string; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Day0/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | func main() { 9 | //bufio package is used to help reading from Stdin 10 | reader := bufio.NewReader(os.Stdin) 11 | //Read a line from Stdin into the 'input' variable 12 | input, _ := reader.ReadString('\n') 13 | 14 | fmt.Println("Hello, World.") 15 | fmt.Println(input) 16 | } 17 | -------------------------------------------------------------------------------- /Day0/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public static void main(String[] args) { 3 | Scanner scan = new Scanner(System.in); // use the Scanner class to read from stdin 4 | String inputString = scan.nextLine(); // read a line of input and save it to a variable 5 | scan.close(); // close the scanner 6 | 7 | // Your first line of output goes here 8 | System.out.println("Hello, World."); 9 | 10 | // Write the second line of output 11 | System.out.println(inputString); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Day0/Solution.py: -------------------------------------------------------------------------------- 1 | #Compatible with python3 2 | # Read a full line of input from stdin and save it to our dynamically typed variable, input_string. 3 | inputString = input() 4 | 5 | # Print a string literal saying "Hello, World." to stdout. 6 | print('Hello, World.') 7 | print(inputString) 8 | -------------------------------------------------------------------------------- /Day0/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() { 4 | let mut input_string = String::new(); 5 | 6 | io::stdin().read_line(&mut input_string) 7 | .expect("Failed to read line!"); 8 | 9 | println!("Hello, World."); 10 | println!("{}", input_string); 11 | } -------------------------------------------------------------------------------- /Day0/Solution.swift: -------------------------------------------------------------------------------- 1 | let inputString = readLine()! 2 | 3 | print("Hello, World.") 4 | print(inputString) 5 | -------------------------------------------------------------------------------- /Day1/Solution.c: -------------------------------------------------------------------------------- 1 | // Declare second integer, double, and String variables. 2 | int j; 3 | double e; 4 | char t[1000]; 5 | 6 | // Read and save an integer, double, and String to your variables. 7 | scanf("%d%lf", &j,&e); 8 | getchar(); 9 | scanf("%[^\n]s", t); 10 | // Print the sum of both integer variables and double variables on a new line. 11 | printf("%d\n%.1lf\n",(i+j), (d+e)); 12 | printf("%s%s", s,t); 13 | -------------------------------------------------------------------------------- /Day1/Solution.cpp: -------------------------------------------------------------------------------- 1 | // Declare second integer, double, and String variables. 2 | int j; 3 | double e; 4 | string t; 5 | 6 | // Read and save an integer, double, and String to your variables. 7 | cin >> j; 8 | cin >> e; 9 | cin.get(); 10 | getline(cin, t); 11 | // Print the sum of both integer variables on a new line. 12 | cout<< i+j << endl; 13 | // Print the sum of the double variables on a new line. 14 | d = d+e; 15 | cout<< std::fixed <0) 8 | { 9 | if(n%2==1) 10 | count++; 11 | else 12 | count = 0; 13 | if(max> n; 4 | int max = 0; 5 | int count = 0; 6 | 7 | while(n>0) 8 | { 9 | if(n%2==1) 10 | count++; 11 | else 12 | count = 0; 13 | if(max0{ 12 | if(n%2 == 1){ 13 | count++ 14 | } else{ 15 | count = 0 16 | } 17 | 18 | if(max0) 10 | { 11 | if(n%2==1) 12 | count++; 13 | else 14 | count = 0; 15 | if(maxb else b 7 | 8 | n = int(input().strip()) 9 | 10 | max_num = 0 11 | count = 0 12 | 13 | while n: 14 | while n&1: 15 | count += 1 16 | n>>=1 17 | max_num = max(count, max_num) 18 | if not n&1: 19 | count = 0 20 | n>>=1 21 | 22 | print(max_num) 23 | -------------------------------------------------------------------------------- /Day10/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() { 4 | let mut input = String::new(); 5 | match io::stdin().read_line(&mut input){ 6 | Ok(_) => { 7 | match input.trim().parse::() { 8 | Ok(number) => { 9 | println!("{0}", max_consecutive_ones(number)); 10 | } 11 | Err(error) => { 12 | panic!("{:?}", error); 13 | } 14 | } 15 | }, 16 | Err(error) => { 17 | panic!("{:?}", error); 18 | } 19 | } 20 | } 21 | 22 | fn max_consecutive_ones(mut n : i32) -> i32{ 23 | let mut max = 0; 24 | let mut ones = 0; 25 | while n > 0 { 26 | ones = (ones + 1) * (n%2); 27 | if max < ones { 28 | max = ones; 29 | } 30 | n /= 2; 31 | 32 | } 33 | max 34 | } -------------------------------------------------------------------------------- /Day10/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | guard let n = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!) 4 | else { fatalError("Bad input") } 5 | 6 | var binary = String(n, radix: 2) 7 | let ones = binary.components(separatedBy: "0") 8 | var highestCount = 0 9 | 10 | for i in ones { 11 | if(i.count > highestCount) { 12 | highestCount = i.count 13 | } 14 | } 15 | 16 | print(highestCount) 17 | -------------------------------------------------------------------------------- /Day11/Solution.c: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int arr[6][6]; 3 | for(int arr_i = 0; arr_i < 6; arr_i++){ 4 | for(int arr_j = 0; arr_j < 6; arr_j++){ 5 | 6 | scanf("%d",&arr[arr_i][arr_j]); 7 | } 8 | } 9 | int i,j,max; 10 | for(i=0;i<4;i++) 11 | { 12 | for(j=0;j<4;j++) 13 | { 14 | int sum=0; 15 | sum= arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2]; 16 | if(i==0 && j==0) 17 | max = sum; 18 | if(sum>max) 19 | { 20 | max =sum; 21 | 22 | } 23 | } 24 | } 25 | printf("%d",max); 26 | 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Day11/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | vector< vector > arr(6,vector(6)); 3 | for(int arr_i = 0;arr_i < 6;arr_i++){ 4 | for(int arr_j = 0;arr_j < 6;arr_j++){ 5 | cin >> arr[arr_i][arr_j]; 6 | } 7 | } 8 | 9 | int i,j,max; 10 | for(i=0;i<4;i++) 11 | { 12 | for(j=0;j<4;j++) 13 | { 14 | int sum=0; 15 | sum= arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2]; 16 | if(i==0 && j==0) 17 | max = sum; 18 | if(sum>max) 19 | { 20 | max =sum; 21 | 22 | } 23 | } 24 | } 25 | cout << max; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Day11/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "io" 7 | "math" 8 | "os" 9 | "strconv" 10 | "strings" 11 | ) 12 | 13 | func main() { 14 | reader := bufio.NewReaderSize(os.Stdin, 1024*1024) 15 | 16 | var arr [][]int32 17 | for i := 0; i < 6; i++ { 18 | arrRowTemp := strings.Split(readLine(reader), " ") 19 | 20 | var arrRow []int32 21 | for _, arrRowItem := range arrRowTemp { 22 | arrItemTemp, err := strconv.ParseInt(arrRowItem, 10, 64) 23 | checkError(err) 24 | arrItem := int32(arrItemTemp) 25 | arrRow = append(arrRow, arrItem) 26 | } 27 | 28 | if len(arrRow) != int(6) { 29 | panic("Bad input") 30 | } 31 | 32 | arr = append(arr, arrRow) 33 | } 34 | 35 | max := int32(math.MinInt32) 36 | for i := 1; i < 5; i++ { 37 | for j := 1; j < 5; j++ { 38 | temp := arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1] + arr[i][j] + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1] 39 | if temp > max { 40 | max = temp 41 | } 42 | } 43 | } 44 | fmt.Println(max) 45 | } 46 | 47 | func readLine(reader *bufio.Reader) string { 48 | str, _, err := reader.ReadLine() 49 | if err == io.EOF { 50 | return "" 51 | } 52 | 53 | return strings.TrimRight(string(str), "\r\n") 54 | } 55 | 56 | func checkError(err error) { 57 | if err != nil { 58 | panic(err) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Day11/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | Scanner in = new Scanner(System.in); 5 | int arr[][] = new int[6][6]; 6 | for(int i=0; i < 6; i++){ 7 | for(int j=0; j < 6; j++){ 8 | arr[i][j] = in.nextInt(); 9 | } 10 | } 11 | 12 | int max = -65; // max is initialized -65 because if all element all -9 their sum will be -65 no hour glass can have sum less than this 13 | for(int i=0;i<4;i++) 14 | { 15 | for(int j=0;j<4;j++) 16 | { 17 | int sum=0; 18 | sum= arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2]; 19 | 20 | if(sum>max) 21 | { 22 | max =sum; 23 | 24 | } 25 | } 26 | } 27 | System.out.println(max); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Day11/Solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | 6 | arr = [] 7 | for arr_i in range(6): 8 | arr_temp = list(map(int,input().strip().split(' '))) 9 | arr.append(arr_temp) 10 | max = 0 11 | 12 | for i in range(0,4): 13 | for j in range(0,4): 14 | sum = 0 15 | sum= arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2] 16 | if i==0 and j==0: 17 | max = sum 18 | if sum > max: 19 | max =sum 20 | 21 | print(max) -------------------------------------------------------------------------------- /Day11/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() { 4 | let mut array = [[0;6];6]; 5 | for i in &mut array { 6 | let mut input_row = String::new(); 7 | match io::stdin().read_line(&mut input_row){ 8 | Ok(_) => { 9 | for (j, value) in input_row.trim().split(' ').enumerate() { 10 | match value.parse::() { 11 | Ok(number) => { 12 | i[j] = number; 13 | }, 14 | Err(error) => { 15 | panic!("{:?}", error); 16 | } 17 | } 18 | } 19 | }, 20 | Err(error) => { 21 | panic!("{:?}", error); 22 | } 23 | } 24 | } 25 | 26 | println!("{0}", max_hourglass_sum(&array)); 27 | } 28 | 29 | fn max_hourglass_sum(a: &[[i32; 6]; 6]) -> i32 { 30 | let mut max = -63; 31 | for i in 1..5 { 32 | for j in 1..5 { 33 | let sum = a[i][j] + a[i-1][j] + a[i-1][j-1] + a[i-1][j+1] + a[i+1][j] + a[i+1][j-1] + a[i+1][j+1]; 34 | if sum > max { 35 | max = sum; 36 | } 37 | } 38 | } 39 | return max; 40 | } 41 | -------------------------------------------------------------------------------- /Day11/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | //To create a 6x6 2D Array. 4 | var arr = Array(repeating: Array( repeating: 0, count: 6), count: 6) 5 | 6 | //To fill i and j values into matrix which is 0 to 5. 7 | for i in stride(from: 0, through: 5, by: 1) { 8 | let value = readLine()!.components(separatedBy: " ").map{Int($0)!} 9 | arr[i] = value.map {Int($0)} 10 | } 11 | 12 | //To calculate the largest (maximum) hourglass sum 13 | var maxHourglassSum = -9 * 7; 14 | for i in stride(from: 0, through: 5, by: 1) { 15 | for j in stride(from: 0, through: 5, by: 1) { 16 | if j + 2 < 6 && i + 2 < 6 { 17 | let top = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] 18 | let mid = arr[i + 1][j + 1] 19 | let bot = arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2]; 20 | let sum = top + mid + bot 21 | if sum > maxHourglassSum { 22 | maxHourglassSum = sum 23 | } 24 | } 25 | } 26 | } 27 | 28 | //To print maximum hourglass sum 29 | print(maxHourglassSum) 30 | -------------------------------------------------------------------------------- /Day12/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Student : public Person{ 2 | private: 3 | vector testScores; 4 | public: 5 | 6 | Student(string firstName,string lastName,int id,vector scores): Person(firstName, lastName, id) { 7 | 8 | this->testScores = scores; 9 | } 10 | 11 | char calculate(){ 12 | double avg = 0.0; 13 | for(int i=0;i Character { 54 | var total = 0; 55 | for testScore in testScores { total += testScore; } 56 | let avg = total / testScores.count; 57 | if avg >= 90 && avg <= 100 { 58 | return "O" 59 | } 60 | if avg >= 80 && avg < 90 { 61 | return "E" 62 | } 63 | if avg >= 70 && avg < 80 { 64 | return "A" 65 | } 66 | if avg >= 55 && avg < 70 { 67 | return "P" 68 | } 69 | if avg >= 40 && avg < 55 { 70 | return "D" 71 | } 72 | return "T" 73 | } 74 | } // End of class Student 75 | 76 | //Take input of student`s firstName, lastName, id and scores 77 | let nameAndID = readLine()!.components(separatedBy: " ") 78 | let _ = readLine() 79 | let scores = readLine()!.components(separatedBy: " ").map{ Int($0)! } 80 | 81 | //Create Student class instance 82 | let s = Student(firstName: nameAndID[0], lastName: nameAndID[1], id: Int(nameAndID[2])!, scores: scores) 83 | s.printPerson() 84 | print("Grade: \(s.calculate())") 85 | -------------------------------------------------------------------------------- /Day13/Solution.cpp: -------------------------------------------------------------------------------- 1 | class MyBook:public Book { 2 | 3 | int price; 4 | public: 5 | MyBook(string title, string author, int p):Book(title, author) { 6 | price = p; 7 | } 8 | 9 | void display() { 10 | cout<<"Title: "< v) { 2 | elements = v; 3 | } 4 | 5 | void computeDifference(){ 6 | maximumDifference = 0; 7 | for(int i=0;imaximumDifference) 12 | { 13 | maximumDifference = abs(elements[i]-elements[j]); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Day14/Solution.java: -------------------------------------------------------------------------------- 1 | Difference(int[] arr){ 2 | this.elements = arr; 3 | } 4 | public void computeDifference(){ 5 | maximumDifference =0; 6 | for(int i=0;imaximumDifference) 11 | { 12 | maximumDifference = Math.abs(elements[i]-elements[j]); 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day14/Solution.py: -------------------------------------------------------------------------------- 1 | class Difference: 2 | def __init__(self, a): 3 | self.elements=a 4 | self.maximumDifference = 0 5 | 6 | def computeDifference(self): 7 | self.maximumDifference=max(a)-min(a) 8 | -------------------------------------------------------------------------------- /Day14/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | class Difference { 4 | private var elements = [Int]() 5 | var maximumDifference: Int 6 | 7 | /* 8 | * Initializer 9 | * 10 | * Parameters: 11 | * a - A array of integers denoting the elements. 12 | */ 13 | init(a: [Int]) { 14 | self.elements = a 15 | self.maximumDifference = 0 16 | } 17 | 18 | //To compute the maximum difference 19 | func computeDifference() { 20 | 21 | //To Satisfies constraint specified in task 22 | guard elements.count >= 1, elements.count <= 100 else { return } 23 | 24 | //To sort the array in ascending order 25 | elements.sort{$0 < $1} 26 | 27 | //To compute the difference between greatest and least in the array. 28 | maximumDifference = elements.last! - elements.first! 29 | } 30 | } // End of Difference class 31 | 32 | //Take input elements 33 | let n = Int(readLine()!)! 34 | let a = readLine()!.components(separatedBy: " ").map{ Int($0)! } 35 | 36 | //Create Difference class instance 37 | let d = Difference(a: a) 38 | d.computeDifference() 39 | print(d.maximumDifference) 40 | -------------------------------------------------------------------------------- /Day15/Solution.c: -------------------------------------------------------------------------------- 1 | Node* insert(Node *head,int data) 2 | { 3 | //Complete this function 4 | 5 | 6 | Node *ptr, *temp = head; 7 | 8 | ptr = (struct ptr *) malloc (sizeof(struct Node)); 9 | 10 | ptr -> data = data; 11 | ptr -> next = NULL; 12 | 13 | if(temp == NULL){ 14 | 15 | head = ptr; 16 | } 17 | 18 | else{ 19 | 20 | while(temp -> next != NULL){ 21 | 22 | temp = temp -> next; 23 | } 24 | 25 | temp -> next = ptr; 26 | } 27 | 28 | return head; 29 | } 30 | -------------------------------------------------------------------------------- /Day15/Solution.cpp: -------------------------------------------------------------------------------- 1 | Node* insert(Node *head,int data) 2 | { 3 | Node* new_node; 4 | new_node = new Node(data); 5 | if (head == NULL){ 6 | head = new_node; 7 | } 8 | else { 9 | Node* temp; 10 | temp = head; 11 | while (temp->next!=NULL){ 12 | temp = temp->next; 13 | } 14 | temp->next = new_node; 15 | } 16 | 17 | return head; 18 | } 19 | -------------------------------------------------------------------------------- /Day15/Solution.java: -------------------------------------------------------------------------------- 1 | public static Node insert(Node head,int data) 2 | { 3 | //Complete this method 4 | Node n = new Node(data); 5 | Node temp=head; 6 | if(head==null) 7 | return n; 8 | else{ 9 | while(temp.next !=null) 10 | temp = temp.next; 11 | } 12 | temp.next=n; 13 | return head; 14 | } 15 | -------------------------------------------------------------------------------- /Day15/Solution.py: -------------------------------------------------------------------------------- 1 | def insert(self,head,data): 2 | if head is None: 3 | head = Node(data) 4 | elif head.next is None: 5 | head.next = Node(data) 6 | else: 7 | self.insert(head.next, data) 8 | return head 9 | -------------------------------------------------------------------------------- /Day15/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | class Node { 4 | let data: Int 5 | var next: Node? 6 | 7 | init(data: Int) { 8 | self.data = data 9 | } 10 | } 11 | 12 | func insert(head: Node?, data: Int!) -> Node? { 13 | var head = head 14 | if head == nil {head = Node(data: data)} else { 15 | var currentNode: Node = head! 16 | while currentNode.next != nil {currentNode = currentNode.next!} 17 | currentNode.next = Node(data: data) 18 | } 19 | return head! 20 | } 21 | 22 | func display(head: Node?) { 23 | var current = head 24 | 25 | while current != nil { 26 | print(current!.data, terminator: " ") 27 | current = current!.next 28 | } 29 | } 30 | 31 | var head: Node? 32 | let n: Int = Int(readLine()!)! 33 | 34 | for _ in 0..> S; 4 | try { 5 | int result = stoi(S); 6 | cout< Int { 2 | 3 | guard let result = Int(inputString) else { 4 | throw StringToIntTypecastingError.BadString 5 | } 6 | return result 7 | 8 | } -------------------------------------------------------------------------------- /Day17/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Calculator: public exception { 2 | 3 | public: 4 | const char * what () const throw(){ 5 | return "n and p should be non-negative"; 6 | } 7 | int power(int n, int p){ 8 | if (n<0 || p<0){ 9 | throw Calculator(); 10 | } 11 | else { 12 | return pow(n,p); 13 | } 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Day17/Solution.java: -------------------------------------------------------------------------------- 1 | class Calculator { 2 | 3 | public int power(int n, int p)throws Exception{ 4 | if(n<0 || p<0){ 5 | throw new Exception("n and p should be non-negative"); 6 | } 7 | else 8 | return (int)Math.pow(n, p); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Day17/Solution.py: -------------------------------------------------------------------------------- 1 | class Calculator(Exception): 2 | def power(self,n,p): 3 | if (n<0 or p<0): 4 | raise Calculator("n and p should be non-negative") 5 | else: 6 | return pow(n,p) 7 | 8 | -------------------------------------------------------------------------------- /Day17/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // Defining enum for throwing error 4 | // throw RangeError.NotInRange... is used to throw the error 5 | enum RangeError : Error { 6 | case NotInRange(String) 7 | } 8 | 9 | // Start of class Calculator 10 | class Calculator { 11 | // Start of function power 12 | func power(n: Int, p: Int) throws -> Int { 13 | // Add your code here 14 | if(n < 0 || p < 0) { 15 | throw RangeError.NotInRange("n and p should be non-negative") 16 | } else if (p == 0) { 17 | return 1 18 | } else { 19 | var total = 1; 20 | for i in 1...p { 21 | total *= n 22 | } 23 | return total 24 | } 25 | } // End of function power 26 | } // End of class Calculator 27 | 28 | let myCalculator = Calculator() 29 | -------------------------------------------------------------------------------- /Day18/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | stack s; 3 | queue q; 4 | public: 5 | // push Character 6 | void pushCharacter(char ch){ 7 | s.push(ch); 8 | } 9 | 10 | // enqueue charactor 11 | void enqueueCharacter(char ch){ 12 | q.push(ch); 13 | } 14 | 15 | // pop Character 16 | char popCharacter(){ 17 | char c = s.top(); 18 | s.pop(); 19 | return c; 20 | } 21 | 22 | // dequeue Character 23 | char dequeueCharacter(){ 24 | char c = q.front(); 25 | q.pop(); 26 | return c; 27 | 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Day18/Solution.java: -------------------------------------------------------------------------------- 1 | // declarations 2 | LinkedList s = new LinkedList(); 3 | LinkedList q = new LinkedList(); 4 | 5 | // push Character 6 | public void pushCharacter(char ch){ 7 | s.add(ch); 8 | } 9 | 10 | // enqueue charactor 11 | public void enqueueCharacter(char ch){ 12 | q.add(ch); 13 | } 14 | 15 | // pop Character 16 | public char popCharacter(){ 17 | return (char) s.removeLast(); 18 | } 19 | 20 | // dequeue Character 21 | public char dequeueCharacter(){ 22 | return (char) q.removeFirst(); 23 | } 24 | -------------------------------------------------------------------------------- /Day18/Solution.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | class Solution: 4 | def __init__(self): 5 | self.stack = deque() 6 | self.queue = deque() 7 | 8 | def pushCharacter(self,char): 9 | self.stack.append(char) 10 | 11 | def popCharacter(self): 12 | return self.stack.pop() 13 | 14 | def enqueueCharacter(self,char): 15 | self.queue.append(char) 16 | 17 | def dequeueCharacter(self): 18 | return self.queue.popleft(); 19 | -------------------------------------------------------------------------------- /Day18/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | class Solution { 4 | //Write your code here 5 | var stack = [Character]() 6 | var queue = [Character]() 7 | 8 | func pushCharacter(ch: Character){ 9 | self.stack.append(ch) 10 | } 11 | 12 | func enqueueCharacter(ch: Character){ 13 | self.queue.append(ch) 14 | } 15 | 16 | func popCharacter() -> Character { 17 | let first = self.stack[0] 18 | self.stack.removeFirst() 19 | return first 20 | } 21 | 22 | func dequeueCharacter() -> Character { 23 | let last = self.queue[self.queue.count - 1] 24 | self.queue.removeLast() 25 | return last 26 | } 27 | } 28 | 29 | // read the string s. 30 | let s = readLine()! 31 | 32 | // create the Solution class object p. 33 | let obj = Solution() 34 | 35 | // push/enqueue all the characters of string s to stack. 36 | for character in s { 37 | obj.pushCharacter(ch: character) 38 | obj.enqueueCharacter(ch: character) 39 | } 40 | 41 | 42 | var isPalindrome = true 43 | 44 | // pop the top character from stack. 45 | // dequeue the first character from queue. 46 | // compare both the characters. 47 | for _ in 0..<(s.count / 2) { 48 | if obj.popCharacter() != obj.dequeueCharacter() { 49 | isPalindrome = false 50 | 51 | break 52 | } 53 | } 54 | 55 | // finally print whether string s is palindrome or not. 56 | if isPalindrome { 57 | print("The word, \(s), is a palindrome.") 58 | } else { 59 | print("The word, \(s), is not a palindrome.") 60 | } 61 | -------------------------------------------------------------------------------- /Day19/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Calculator: public AdvancedArithmetic{ 2 | int sum =1; 3 | public: 4 | int divisorSum(int num){ 5 | for (int i=2;i<=num;i++){ 6 | if (num%i==0){ 7 | sum +=i; 8 | } 9 | } 10 | return sum; 11 | } 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /Day19/Solution.java: -------------------------------------------------------------------------------- 1 | class Calculator implements AdvancedArithmetic{ 2 | 3 | public int divisorSum(int n){ 4 | int divisorSum=n; 5 | for(int i=1;i>mealcost>>tip>>tax; 6 | tip=tip*mealcost/100; 7 | tax=tax*mealcost/100; 8 | totalcost=mealcost+tip+tax; 9 | cout<<"The total meal cost is "< Void { 5 | let tip = (meal_cost * (Double(tip_percent)/100)) 6 | let tax = (meal_cost * (Double(tax_percent)/100)) 7 | let mealCost = meal_cost + tip + tax 8 | 9 | // cast the result of the rounding operation to an int and save it as totalCost 10 | let totalCost = Int(round(mealCost)) 11 | 12 | // Print your result 13 | print(totalCost) 14 | } 15 | -------------------------------------------------------------------------------- /Day20/Solution.c: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int n; 3 | scanf("%d",&n); 4 | int *a = malloc(sizeof(int) * n); 5 | for(int a_i = 0; a_i < n; a_i++){ 6 | scanf("%d",&a[a_i]); 7 | } 8 | int numberOfSwaps = 0; 9 | for (int i = 0; i < n; i++) { 10 | 11 | for (int j = 0; j < n - 1; j++) { 12 | if (a[j] > a[j + 1]) { 13 | int temp=a[j]; 14 | a[j] = a[j+1]; 15 | a[j+1] = temp; 16 | numberOfSwaps++; 17 | } 18 | } 19 | if (numberOfSwaps == 0) { 20 | break; 21 | } 22 | } 23 | printf("Array is sorted in %d swaps.\n", numberOfSwaps); 24 | printf("First Element: %d\n", a[0]) ; 25 | printf("Last Element: %d\n", a[n-1]); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Day20/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int n; 3 | cin >> n; 4 | vector a(n); 5 | for(int a_i = 0;a_i < n;a_i++){ 6 | cin >> a[a_i]; 7 | } 8 | int numberOfSwaps = 0; 9 | for (int i = 0; i < n; i++) { 10 | 11 | for (int j = 0; j < n - 1; j++) { 12 | if (a[j] > a[j + 1]) { 13 | int temp=a[j]; 14 | a[j] = a[j+1]; 15 | a[j+1] = temp; 16 | numberOfSwaps++; 17 | } 18 | } 19 | if (numberOfSwaps == 0) { 20 | break; 21 | } 22 | } 23 | cout << "Array is sorted in "<< numberOfSwaps << " swaps." < arr[j+1] { 23 | arr[j], arr[j+1] = arr[j+1], arr[j] 24 | numberOfSwaps += 1 25 | totalSwaps += 1 26 | } 27 | } 28 | 29 | // If no elements were swapped during a traversal, array is sorted 30 | if (numberOfSwaps == 0) { 31 | break; 32 | } 33 | } 34 | 35 | fmt.Printf("Array is sorted in %d swaps.\n", totalSwaps) 36 | fmt.Printf("First Element: %d\n",arr[0]) 37 | fmt.Printf("Last Element: %d",arr[n-1]) 38 | } 39 | -------------------------------------------------------------------------------- /Day20/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | Scanner in = new Scanner(System.in); 5 | int n = in.nextInt(); 6 | int a[] = new int[n]; 7 | for(int a_i=0; a_i < n; a_i++){ 8 | a[a_i] = in.nextInt(); 9 | } 10 | int numberOfSwaps = 0; 11 | for (int i = 0; i < n; i++) { 12 | 13 | for (int j = 0; j < n - 1; j++) { 14 | if (a[j] > a[j + 1]) { 15 | int temp=a[j]; 16 | a[j] = a[j+1]; 17 | a[j+1] = temp; 18 | numberOfSwaps++; 19 | } 20 | } 21 | if (numberOfSwaps == 0) { 22 | break; 23 | } 24 | } 25 | System.out.println("Array is sorted in " + numberOfSwaps + " swaps."); 26 | System.out.println("First Element: " + a[0]); 27 | System.out.println("Last Element: " + a[n-1]); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Day20/Solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | 6 | n = int(input().strip()) 7 | a = list(map(int, input().strip().split(' '))) 8 | numberOfSwaps = 0 9 | for i in range(0,n): 10 | for j in range(0, n-1): 11 | if (a[j] > a[j + 1]): 12 | temp=a[j] 13 | a[j] = a[j+1] 14 | a[j+1] = temp 15 | numberOfSwaps += 1 16 | if (numberOfSwaps == 0): 17 | break 18 | print( "Array is sorted in " + str(numberOfSwaps) + " swaps." ) 19 | print( "First Element: " + str(a[0]) ) 20 | print( "Last Element: " + str(a[n-1]) ) 21 | -------------------------------------------------------------------------------- /Day20/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() { 4 | let mut input_size = String::new(); 5 | let n; 6 | match io::stdin().read_line(&mut input_size){ 7 | Ok(_) => { 8 | match input_size.trim().parse::() { 9 | Ok(number) => { 10 | n = number; 11 | } 12 | Err(error) => { 13 | panic!("{:?}", error); 14 | } 15 | } 16 | }, 17 | Err(error) => { 18 | panic!("{:?}", error); 19 | } 20 | } 21 | 22 | let mut input_array = String::new(); 23 | let mut a = Vec::new(); 24 | match io::stdin().read_line(&mut input_array){ 25 | Ok(_) => { 26 | for value in input_array.trim().split(' ') { 27 | match value.parse::() { 28 | Ok(number) => { 29 | a.push(number); 30 | }, 31 | Err(error) => { 32 | panic!("{:?}", error); 33 | } 34 | } 35 | } 36 | }, 37 | Err(error) => { 38 | panic!("{:?}", error); 39 | } 40 | } 41 | 42 | println!("Array is sorted in {0} swaps.", bubble_sort(n, &mut a)); 43 | println!("First Element: {0}", a[0]); 44 | println!("Last Element: {0}", a[n-1]); 45 | } 46 | 47 | fn bubble_sort(n : usize, a : &mut Vec) -> u32{ 48 | 49 | let mut swaps = 0; 50 | 51 | for _i in 0..n { 52 | let mut single_traversal_swaps = 0; 53 | for j in 0..n-1 { 54 | if a[j] > a[j+1] { 55 | a.swap(j, j+1); 56 | single_traversal_swaps += 1; 57 | } 58 | } 59 | 60 | if single_traversal_swaps == 0 { 61 | break; 62 | } 63 | 64 | swaps += single_traversal_swaps; 65 | } 66 | 67 | swaps 68 | } -------------------------------------------------------------------------------- /Day20/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // read the integer n 4 | let n = Int(readLine()!)! 5 | 6 | // read the array 7 | var arr = readLine()!.components(separatedBy: " ").map{ Int($0)! } 8 | 9 | var totalSwaps = 0 10 | 11 | for i in 0...n - 1 { 12 | // Track number of elements swapped during a single array traversal 13 | var numberOfSwaps = 0 14 | 15 | for j in 0...n - 2 { 16 | // Swap adjacent elements if they are in decreasing order 17 | if (arr[j] > arr[j + 1]) { 18 | arr.swapAt(j, j + 1) 19 | numberOfSwaps += 1 20 | totalSwaps += 1 21 | } 22 | } 23 | 24 | // If no elements were swapped during a traversal, array is sorted 25 | if (numberOfSwaps == 0) { 26 | break; 27 | } 28 | } 29 | 30 | print("Array is sorted in \(totalSwaps) swaps.") 31 | print("First Element: \(arr[0])") 32 | print("Last Element: \(arr[n - 1])") 33 | -------------------------------------------------------------------------------- /Day21/Solution.cpp: -------------------------------------------------------------------------------- 1 | template 2 | void printArray(vector v) { 3 | for(int i=0;i void printArray(E[] array){ 2 | 3 | for(E element : array){ 4 | System.out.println(element); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Day21/Solution.swift: -------------------------------------------------------------------------------- 1 | // Write your code here 2 | func printArray(array: [T]) { 3 | array.forEach { print($0 )} 4 | } 5 | -------------------------------------------------------------------------------- /Day22/Solution.c: -------------------------------------------------------------------------------- 1 | int getHeight(Node* root){ 2 | if(root== NULL){ 3 | return -1; 4 | } 5 | else{ 6 | int a = getHeight(root->left); 7 | int b = getHeight(root->right); 8 | if(a>b) 9 | return 1+a; 10 | else 11 | return 1+b; 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Day22/Solution.cpp: -------------------------------------------------------------------------------- 1 | int getHeight(Node* root){ 2 | if(root== NULL){ 3 | return -1; 4 | } 5 | else{ 6 | int a = getHeight(root->left); 7 | int b = getHeight(root->right); 8 | if(a>b) 9 | return 1+a; 10 | else 11 | return 1+b; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Day22/Solution.java: -------------------------------------------------------------------------------- 1 | public static int getHeight(Node root){ 2 | 3 | if(root== null){ 4 | return -1; 5 | } 6 | else{ 7 | int a = getHeight(root.left); 8 | int b = getHeight(root.right); 9 | if(a>b) 10 | return 1+a; 11 | else 12 | return 1+b; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Day22/Solution.py: -------------------------------------------------------------------------------- 1 | def getHeight(self,root): 2 | if root is None or (root.left is None and root.right is None): 3 | return 0 4 | else: 5 | return max(self.getHeight(root.left),self.getHeight(root.right))+1 6 | -------------------------------------------------------------------------------- /Day22/Solution.swift: -------------------------------------------------------------------------------- 1 | func getHeight(root: Node?) -> Int { 2 | return root == nil ? -1 : 1 + max(getHeight(root: root?.left), getHeight(root: root?.right)) 3 | } // End of getHeight function 4 | -------------------------------------------------------------------------------- /Day23/Solution.cpp: -------------------------------------------------------------------------------- 1 | void levelOrder(Node * root){ 2 | //Write your code here 3 | if (root == NULL) 4 | return; 5 | queue q; 6 | q.push(root); 7 | while(!q.empty()){ 8 | Node* current = q.front(); 9 | cout<< current->data << " "; 10 | if(current->left != NULL) 11 | q.push(current->left); 12 | 13 | if(current->right !=NULL) 14 | q.push(current->right); 15 | 16 | q.pop(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day23/Solution.java: -------------------------------------------------------------------------------- 1 | static void levelOrder(Node root){ 2 | //Write your code here 3 | if(root == null) 4 | return; 5 | Queue q = new LinkedList(); 6 | q.add(root); 7 | while(q.peek() != null){ 8 | Node current = q.peek(); 9 | System.out.print(current.data + " "); 10 | if (current.left != null) 11 | q.add(current.left); 12 | if (current.right != null) 13 | q.add(current.right); 14 | 15 | q.remove(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day23/Solution.py: -------------------------------------------------------------------------------- 1 | def levelOrder(self,root): 2 | output = "" 3 | queue = [root] 4 | while queue: 5 | current = queue.pop(0) 6 | output += str(current.data) + " " 7 | if current.left: 8 | queue.append(current.left) 9 | if current.right: 10 | queue.append(current.right) 11 | print(output[:-1]) -------------------------------------------------------------------------------- /Day23/Solution.swift: -------------------------------------------------------------------------------- 1 | // Start of Node class 2 | class Node { 3 | var data: Int 4 | var left: Node? 5 | var right: Node? 6 | 7 | init(d : Int) { 8 | data = d 9 | } 10 | } // End of Node class 11 | 12 | // Start of Tree class 13 | class Tree { 14 | func insert(root: Node?, data: Int) -> Node? { 15 | if root == nil { 16 | return Node(d: data) 17 | } 18 | 19 | if data <= (root?.data)! { 20 | root?.left = insert(root: root?.left, data: data) 21 | } else { 22 | root?.right = insert(root: root?.right, data: data) 23 | } 24 | 25 | return root 26 | } 27 | 28 | func levelOrder(root: Node?) -> Void { 29 | // Complete the function 30 | var queue = [Node]() 31 | queue.append(root!) 32 | 33 | while queue.count != 0 { 34 | let currNode = queue.removeFirst() 35 | 36 | print("\(currNode.data) ", terminator: "") 37 | 38 | if currNode.left != nil { 39 | queue.append(currNode.left!) 40 | } 41 | 42 | if currNode.right != nil { 43 | queue.append(currNode.right!) 44 | } 45 | } 46 | } // End of levelOrder function 47 | 48 | 49 | } // End of Tree class 50 | 51 | var root: Node? 52 | let tree = Tree() 53 | 54 | let t = Int(readLine()!)! 55 | 56 | for _ in 0..next != NULL){ 4 | if(current->data == current->next->data){ 5 | current->next = current->next->next; 6 | } 7 | else{ 8 | current = current->next; 9 | } 10 | } 11 | 12 | return head; 13 | } 14 | -------------------------------------------------------------------------------- /Day24/Solution.cpp: -------------------------------------------------------------------------------- 1 | Node* removeDuplicates(Node *head) 2 | { 3 | //Write your code here 4 | Node *current = head; 5 | while(current->next != NULL){ 6 | if(current->data == current->next->data){ 7 | current->next = current->next->next; 8 | } 9 | else{ 10 | current = current->next; 11 | } 12 | } 13 | 14 | return head; 15 | } 16 | -------------------------------------------------------------------------------- /Day24/Solution.java: -------------------------------------------------------------------------------- 1 | public static Node removeDuplicates(Node head) { 2 | //Write your code here 3 | Node current = head; 4 | 5 | while(current.next!= null){ 6 | 7 | if (current.data == current.next.data){ 8 | current.next = current.next.next; 9 | } 10 | else 11 | current = current.next; 12 | 13 | } 14 | 15 | return head; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Day24/Solution.py: -------------------------------------------------------------------------------- 1 | def removeDuplicates(self,head): 2 | #Write your code here 3 | current = head 4 | while (current.next): 5 | if (current.data == current.next.data): 6 | current.next = current.next.next 7 | else: 8 | current = current.next 9 | 10 | return head -------------------------------------------------------------------------------- /Day24/Solution.swift: -------------------------------------------------------------------------------- 1 | func removeDuplicates(head: Node?) -> Node? { 2 | var current = head 3 | while current?.next != nil { 4 | if current?.data == current?.next?.data { 5 | current?.next = current?.next?.next 6 | } else { 7 | current = current?.next 8 | } 9 | } 10 | return head 11 | } // End of function removeDuplicates 12 | -------------------------------------------------------------------------------- /Day25/Solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | int t; 8 | scanf("%d",&t); 9 | for (int i=0; i < t; i++){ 10 | int flag = 0; 11 | int num; 12 | scanf("%d", &num); 13 | if (num < 2){ 14 | printf("Not prime\n"); 15 | } 16 | else 17 | { 18 | for (int j=2; j <= sqrt(num); j++){ 19 | if (num%j == 0){ 20 | flag =1; 21 | break; 22 | } 23 | } 24 | if (flag == 0){ 25 | printf("Prime\n"); 26 | } 27 | else { 28 | printf("Not prime\n"); 29 | } 30 | } 31 | 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Day25/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main() { 2 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 3 | int t; 4 | cin >> t; 5 | for (int i=0; i < t; i++){ 6 | int flag = 0; 7 | int num; 8 | cin >> num; 9 | if (num < 2){ 10 | cout << "Not prime\n"; 11 | } 12 | else 13 | { 14 | for (int j=2; j <= sqrt(num); j++){ 15 | if (num%j == 0){ 16 | flag =1; 17 | break; 18 | } 19 | } 20 | if (flag == 0){ 21 | cout << "Prime\n"; 22 | } 23 | else { 24 | cout << "Not prime\n"; 25 | } 26 | } 27 | 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Day25/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | import( 3 | "fmt" 4 | "math" 5 | ) 6 | 7 | func main() { 8 | //Enter your code here. Read input from STDIN. Print output to STDOUT 9 | var n,number int 10 | 11 | // take the inputs 12 | fmt.Scanf("%d", &n) 13 | for i:=0; i().expect("Not a valid integer"); 8 | for _ in 0..number_of_tests { 9 | input.clear(); 10 | io::stdin().read_line(&mut input).expect("Not a valid string"); 11 | let num = input.trim_end().parse::().expect("Not a valid integer"); 12 | result.push(is_prime(num)); 13 | } 14 | result.iter().for_each(|&res| println!("{}", if res {"Prime"} else {"Not prime"})); 15 | } 16 | 17 | //based on 6k ± 1 optimization 18 | fn is_prime(n: u32) -> bool { 19 | if n <= 3 { 20 | return n > 1; 21 | } else if (n%2 == 0) || (n%3 == 0) { 22 | return false; 23 | } 24 | let mut i = 5; 25 | while i*i <= n { 26 | if (n%i == 0) || (n%(i+2) == 0) { 27 | return false; 28 | } 29 | i = i + 6; 30 | } 31 | true 32 | } 33 | -------------------------------------------------------------------------------- /Day25/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension Int { 4 | func isPrime() -> Bool { 5 | guard self >= 2 else { return false } 6 | guard self != 2 else { return true } 7 | let max = Int(ceil(sqrt(Double(self)))) 8 | 9 | for number in 2...max { 10 | if self % number == 0 { return false } 11 | } 12 | return true 13 | } 14 | } 15 | 16 | let testCases = Int(readLine() ?? "") ?? 0 17 | 18 | for _ in 0..>da>>ma>>ya; 5 | cin>>de>>me>>ye; 6 | 7 | int fine = 0; 8 | if(ye==ya){ 9 | 10 | if(me < ma){ 11 | fine = (ma - me) * 500; 12 | } 13 | else if( (me == ma) && (de < da) ){ 14 | fine = (da - de) * 15; 15 | } 16 | 17 | } 18 | else if(ye < ya){ 19 | fine = 10000; 20 | } 21 | cout< Vec { 17 | let mut input = String::new(); 18 | io::stdin().read_line(&mut input).expect("Not a valid string"); 19 | input.split_whitespace() 20 | .filter_map(|i| i.parse().ok()) 21 | .collect() 22 | } 23 | 24 | fn calculate_fine(day_diff: i32, month_diff: i32, year_diff: i32) -> i32 { 25 | let mut result = 0; 26 | if year_diff > 0 { 27 | result = 10_000; 28 | } else if year_diff == 0 { 29 | if month_diff > 0 { 30 | result = 500 * month_diff; 31 | } else if month_diff == 0 && day_diff > 0 { 32 | result = 15 * day_diff; 33 | } 34 | } 35 | result 36 | } 37 | -------------------------------------------------------------------------------- /Day26/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | struct LibraryDate { 4 | let day: UInt16 5 | let month: UInt16 6 | let year: UInt16 7 | } 8 | 9 | let input1 = readLine()?.split(separator: " ").map {UInt16($0)} 10 | let input2 = readLine()?.split(separator: " ").map {UInt16($0)} 11 | 12 | let returnedDate = LibraryDate(day: input1?[0] ?? 0, month: input1?[1] ?? 1, year: input1?[2] ?? 1) 13 | let dueDate = LibraryDate(day: input2?[0] ?? 0, month: input2?[1] ?? 1, year: input2?[2] ?? 1) 14 | 15 | var fine: UInt16 = 0 16 | 17 | if returnedDate.year == dueDate.year { 18 | if (returnedDate.month > dueDate.month) { 19 | fine = (returnedDate.month - dueDate.month) * 500 20 | } else if returnedDate.month == dueDate.month && returnedDate.day > dueDate.day { 21 | fine = (returnedDate.day - dueDate.day) * 15 22 | } 23 | } else if returnedDate.year > dueDate.year { 24 | fine = 10000 25 | } 26 | 27 | print(fine) 28 | -------------------------------------------------------------------------------- /Day27/Solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | printf("3\n"); 5 | printf("4 3\n"); 6 | printf("-1 0 1 4\n"); 7 | printf("5 3\n"); 8 | printf("0 2 -4 -6 9\n"); 9 | printf("6 4\n"); 10 | printf("1 0 -3 4 -2 7\n"); 11 | 12 | int t; 13 | scanf("%d", &t); 14 | for(int a0 = 0; a0 < t; a0++){ 15 | int n; 16 | int k; 17 | int count=0; 18 | scanf("%d%d", &n,&k); 19 | int a[n]; 20 | for(int a_i = 0;a_i < n;a_i++){ 21 | scanf("%d", &a[a_i]); 22 | if(a[a_i]<=0) 23 | count++; 24 | } 25 | if(count>=k) 26 | printf("NO \n"); 27 | else 28 | printf("YES \n"); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Day27/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int minimum_index(vector seq) { 10 | if (seq.empty()) { 11 | throw invalid_argument("Cannot get the minimum value index from an empty sequence"); 12 | } 13 | int min_idx = 0; 14 | for (int i = 1; i < seq.size(); ++i) { 15 | if (seq[i] < seq[min_idx]) { 16 | min_idx = i; 17 | } 18 | } 19 | return min_idx; 20 | } 21 | 22 | class TestDataEmptyArray { 23 | public: 24 | static vector get_array() { 25 | vector vect{}; 26 | return vect; 27 | } 28 | 29 | }; 30 | 31 | class TestDataUniqueValues { 32 | public: 33 | static vector get_array() { 34 | vector vect{ 23,5,8,12,7 }; 35 | return vect; 36 | } 37 | 38 | static int get_expected_result() { 39 | return 1; 40 | } 41 | 42 | }; 43 | 44 | class TestDataExactlyTwoDifferentMinimums { 45 | public: 46 | static vector get_array() { 47 | vector vect{ 9,23,3,8,12,3,7 }; 48 | return vect; 49 | } 50 | 51 | static int get_expected_result() { 52 | return 2; 53 | } 54 | 55 | }; 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Day27/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | static class TestDataEmptyArray { 4 | public static int[] get_array() { 5 | return new int[0]; 6 | } 7 | } 8 | 9 | static class TestDataUniqueValues { 10 | public static int[] get_array() { 11 | return new int[]{11, 3, 7, 2, 4, 86, 13}; 12 | } 13 | 14 | public static int get_expected_result() { 15 | return 3; 16 | } 17 | } 18 | 19 | static class TestDataExactlyTwoDifferentMinimums { 20 | public static int[] get_array() { 21 | return new int[]{13, 12, 321, 61, 67, 34, 12}; 22 | } 23 | 24 | public static int get_expected_result() { 25 | return 1; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Day27/Solution.py: -------------------------------------------------------------------------------- 1 | def minimum_index(seq): 2 | if len(seq) == 0: 3 | raise ValueError("Cannot get the minimum value index from an empty sequence") 4 | min_idx = 0 5 | for i in range(1, len(seq)): 6 | if seq[i] < seq[min_idx]: 7 | min_idx = i 8 | return min_idx 9 | 10 | class TestDataEmptyArray(object): 11 | 12 | @staticmethod 13 | def get_array(): 14 | return [] 15 | 16 | class TestDataUniqueValues(object): 17 | 18 | @staticmethod 19 | def get_array(): 20 | return [7, 4, 3, 8, 14] 21 | 22 | @staticmethod 23 | def get_expected_result(): 24 | return 2 25 | 26 | class TestDataExactlyTwoDifferentMinimums(object): 27 | 28 | @staticmethod 29 | def get_array(): 30 | return [7, 4, 3, 8, 3, 14] 31 | 32 | @staticmethod 33 | def get_expected_result(): 34 | return 2 35 | 36 | 37 | -------------------------------------------------------------------------------- /Day27/TestCase_file.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 4 3 3 | -1 0 1 4 4 | 5 3 5 | 0 2 -4 -6 9 6 | 6 4 7 | 1 0 -3 4 -2 7 8 | -------------------------------------------------------------------------------- /Day28/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | int N; 8 | cin >> N; 9 | list names; 10 | for(int a0 = 0; a0 < N; a0++){ 11 | string firstName; 12 | string emailID; 13 | cin >> firstName >> emailID; 14 | if (regex_match (emailID, regex(".+@gmail.com") )){ 15 | names.push_back(firstName); 16 | } 17 | } 18 | names.sort(); 19 | while (!names.empty()) 20 | { 21 | cout << names.front()< name = new ArrayList(); 9 | for(int a0 = 0; a0 < N; a0++){ 10 | String firstName = in.next(); 11 | String emailID = in.next(); 12 | 13 | m = p.matcher(emailID); 14 | if (m.matches()) { 15 | name.add(firstName); 16 | } 17 | } 18 | 19 | Collections.sort(name); 20 | for(String fname: name){ 21 | System.out.println(fname); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Day28/Solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | import re 5 | 6 | 7 | N = int(input().strip()) 8 | names = [] 9 | for a0 in range(N): 10 | firstName,emailID = input().strip().split(' ') 11 | firstName,emailID = [str(firstName),str(emailID)] 12 | match = re.search(r'[\w\.-]+@gmail.com', emailID) 13 | 14 | if match: 15 | names.append(firstName) 16 | names.sort() 17 | for name in names: 18 | print( name ) 19 | -------------------------------------------------------------------------------- /Day28/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | use regex::Regex; 3 | 4 | fn main() { 5 | let pattern = r".+@gmail\.com"; 6 | let re = Regex::new(pattern).unwrap(); 7 | let mut input = String::new(); 8 | io::stdin().read_line(&mut input).expect("Not a valid string"); 9 | let n = input.trim_end().parse::().expect("Not a valid integer"); 10 | for _ in 0..n { 11 | io::stdin().read_line(&mut input).expect("Not a valid string"); 12 | } 13 | let mut result = input.lines() 14 | .into_iter() 15 | .filter(|line| re.is_match(&line)) 16 | .filter_map(|line| line.split_whitespace().next()) 17 | .collect::>(); 18 | result.sort(); 19 | result.iter().for_each(|name| println!("{}", name)); 20 | } 21 | -------------------------------------------------------------------------------- /Day28/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension NSRegularExpression { 4 | func matches(_ string: String) -> Bool { 5 | let range = NSRange(location: 0, length: string.utf16.count) 6 | return firstMatch(in: string, options: [], range: range) != nil 7 | } 8 | } 9 | 10 | let testCases = Int(readLine() ?? "") ?? 0 11 | let regex = try? NSRegularExpression(pattern: "[a-z]@gmail.com") 12 | var gmailUsers = [String]() 13 | 14 | for _ in 0.. max){ 12 | max = i&j; 13 | } 14 | } 15 | } 16 | printf("%d\n", max); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Day29/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int t; 3 | cin >> t; 4 | for(int a0 = 0; a0 < t; a0++){ 5 | int n; 6 | int k; 7 | cin >> n >> k; 8 | int max = 0; 9 | for(int i=1;i max){ 12 | max = i&j; 13 | } 14 | } 15 | } 16 | cout< max){ 13 | max = i&j; 14 | } 15 | } 16 | } 17 | System.out.println(max); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Day29/Solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | 6 | t = int(input().strip()) 7 | for a0 in range(t): 8 | n, k = input().strip().split(' ') 9 | n, k = [int(n), int(k)] 10 | print(k-1 if ((k-1) | k) <= n else k-2) 11 | -------------------------------------------------------------------------------- /Day29/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() { 4 | let mut result = Vec::new(); 5 | let mut input = String::new(); 6 | io::stdin().read_line(&mut input).expect("Not a valid string"); 7 | let number_of_tests = input.trim_end().parse::().expect("Not a valid integer"); 8 | for _ in 0..number_of_tests { 9 | input.clear(); 10 | io::stdin().read_line(&mut input).expect("Not a valid string"); 11 | let test_input: Vec = input.split_whitespace() 12 | .filter_map(|i| i.parse().ok()) 13 | .collect(); 14 | result.push( test(test_input[0], test_input[1]) ); 15 | } 16 | result.iter().for_each(|num| println!("{}", num)); 17 | } 18 | 19 | fn test(n: u32, k: u32) -> u32 { 20 | let mut max = 0; 21 | for i in 1..n+1 { 22 | for j in i+1..n+1 { 23 | let res = i&j; 24 | if res > max && res < k { 25 | max = res; 26 | } 27 | } 28 | } 29 | max 30 | } 31 | -------------------------------------------------------------------------------- /Day29/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let testCases = Int(readLine() ?? "") ?? 0 4 | var n = 0 5 | var k = 0 6 | 7 | for _ in 0.. max { 15 | max = x & y 16 | } 17 | } 18 | } 19 | print(max) 20 | } 21 | -------------------------------------------------------------------------------- /Day3/Solution.c: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int n; 3 | scanf("%d",&n); 4 | char ans[40]; 5 | 6 | // if 'n' is NOT evenly divisible by 2 (i.e.: n is odd) 7 | if(n%2==1){ 8 | strcpy(ans, "Weird"); 9 | } 10 | else{ 11 | if(n>20) 12 | strcpy(ans, "Not Weird"); 13 | // Complete the code 14 | else{ 15 | if(n>=6) 16 | strcpy(ans, "Weird"); 17 | else 18 | strcpy(ans, "Not Weird"); 19 | } 20 | } 21 | printf("%s", ans); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Day3/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int n; 3 | cin >> n; 4 | string ans; 5 | 6 | // if 'n' is NOT evenly divisible by 2 (i.e.: n is odd) 7 | if(n%2==1){ 8 | ans = "Weird"; 9 | } 10 | else{ 11 | if(n>20) 12 | ans = "Not Weird"; 13 | // Complete the code 14 | else{ 15 | if(n>=6) 16 | ans = "Weird"; 17 | else 18 | ans = "Not Weird"; 19 | } 20 | } 21 | cout << ans; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Day3/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "io" 7 | "os" 8 | "strconv" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024) 14 | 15 | NTemp, err := strconv.ParseInt(readLine(reader), 10, 64) 16 | checkError(err) 17 | N := int32(NTemp) 18 | //print "Weird" if N is odd or (even and in between 6 and 20 inclusive) 19 | if N % 2 == 1 || N >= 6 && N <= 20 { 20 | fmt.Print("Weird") 21 | } else if N >= 2 && N <= 5 || N > 20 { 22 | //print "Not Weird" is N is even and (in between 2 and 5 inclusive or greater than 20 23 | fmt.Print("Not Weird") 24 | } 25 | } 26 | 27 | func readLine(reader *bufio.Reader) string { 28 | str, _, err := reader.ReadLine() 29 | if err == io.EOF { 30 | return "" 31 | } 32 | 33 | return strings.TrimRight(string(str), "\r\n") 34 | } 35 | 36 | func checkError(err error) { 37 | if err != nil { 38 | panic(err) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Day3/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | Scanner scan = new Scanner(System.in); 5 | int n = scan.nextInt(); 6 | scan.close(); 7 | String ans=""; 8 | 9 | // if 'n' is NOT evenly divisible by 2 (i.e.: n is odd) 10 | if(n%2==1){ 11 | ans = "Weird"; 12 | } 13 | else{ 14 | if(n>20) 15 | ans="Not Weird"; 16 | // Complete the code 17 | else{ 18 | if(n>=6) 19 | ans="Weird"; 20 | else 21 | ans="Not Weird"; 22 | } 23 | } 24 | System.out.println(ans); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day3/Solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | # compatible with python3 3 | import sys 4 | 5 | 6 | n = int(input().strip()) 7 | 8 | # if 'n' is NOT evenly divisible by 2 (i.e.: n is odd) 9 | if n%2==1: 10 | ans = "Weird" 11 | 12 | elif n>20: 13 | ans = "Not Weird" 14 | 15 | elif n>=6: 16 | ans = "Weird" 17 | 18 | else: 19 | ans = "Not Weird" 20 | 21 | print(ans) 22 | -------------------------------------------------------------------------------- /Day3/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() { 4 | let mut input = String::new(); 5 | let _ = io::stdin().read_line(&mut input).unwrap(); 6 | let n = input.parse::().unwrap(); 7 | let is_weird = if n % 2 == 1 { 8 | true 9 | } else { 10 | match n { 11 | 2..=5 => false, 12 | 6..=20 => true, 13 | _ => false, 14 | } 15 | }; 16 | if is_weird { 17 | println!("Weird"); 18 | } else { 19 | println!("Not Weird"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Day3/Solution.swift: -------------------------------------------------------------------------------- 1 | let n = Int(readLine()!)! 2 | 3 | if (n%2 == 1) { 4 | print("Weird") 5 | } else { 6 | 7 | if n>20 { 8 | print("Not Weird") 9 | } else { 10 | if n>=6 { 11 | print("Weird") 12 | } else { 13 | print("Not Weird") 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day4/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Person{ 2 | public: 3 | int age; 4 | Person(int initialAge); 5 | void amIOld(); 6 | void yearPasses(); 7 | }; 8 | 9 | 10 | Person::Person(int initialAge){ 11 | // Add some more code to run some checks on initialAge 12 | if(initialAge>0) 13 | age = initialAge; 14 | else{ 15 | cout <<"Age is not valid, setting age to 0.\n"; 16 | age = 0; 17 | } 18 | } 19 | 20 | void Person::amIOld(){ 21 | // Do some computations in here and print out the correct statement to the console 22 | string message; 23 | if(age<13) 24 | message = "You are young."; 25 | else if(age>=13 && age<18) 26 | message = "You are a teenager."; 27 | else 28 | message = "You are old."; 29 | cout << message << endl; 30 | 31 | } 32 | 33 | void Person::yearPasses(){ 34 | // Increment the age of the person in here 35 | age = age + 1; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Day4/Solution.java: -------------------------------------------------------------------------------- 1 | public class Person { 2 | 3 | private int age; 4 | 5 | public Person(int initialAge) { 6 | // Add some more code to run some checks on initialAge 7 | if(initialAge>0) 8 | age = initialAge; 9 | else{ 10 | System.out.println("Age is not valid, setting age to 0."); 11 | age = 0; 12 | } 13 | } 14 | 15 | public void amIOld() { 16 | // Write code determining if this person's age is old and print the correct statement: 17 | String message; 18 | if(age<13) 19 | message = "You are young."; 20 | else if(age<18) 21 | message = "You are a teenager."; 22 | else 23 | message = "You are old."; 24 | System.out.println(message); 25 | } 26 | 27 | public void yearPasses() { 28 | // Increment this person's age. 29 | age = age + 1; 30 | } 31 | -------------------------------------------------------------------------------- /Day4/Solution.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def __init__(self,initialAge): 3 | # Add some more code to run some checks on initialAge 4 | if(initialAge > 0): 5 | self.age = initialAge 6 | else: 7 | print("Age is not valid, setting age to 0.") 8 | self.age = 0 9 | 10 | def amIOld(self): 11 | # Do some computations in here and print out the correct statement to the console 12 | if self.age >= 18: 13 | print("You are old.") 14 | elif self.age >= 13: 15 | print("You are a teenager.") 16 | else: # age < 13 17 | print("You are young.") 18 | 19 | def yearPasses(self): 20 | # Increment the age of the person in here 21 | self.age += 1 22 | -------------------------------------------------------------------------------- /Day4/Solution.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_snake_case)] 2 | 3 | struct Person { 4 | age: i32, 5 | } 6 | 7 | impl Person { 8 | fn new(initialAge: i32) -> Person { 9 | // Add some more code to run some checks on initialAge 10 | if initialAge < 0 { 11 | println!("Age is not valid, setting age to 0."); 12 | return Person { age: 0 }; 13 | } 14 | return Person { age: initialAge }; 15 | } 16 | 17 | fn amIOld(&self) { 18 | let out = match self.age { 19 | age if age < 13 => "You are young.", 20 | age if age < 18 => "You are a teenager.", 21 | _ => "You are old.", 22 | }; 23 | println!("{}", out); 24 | } 25 | 26 | fn yearPasses(&mut self) { 27 | self.age += 1; 28 | } 29 | } 30 | 31 | fn main() { 32 | let T: i32 = read_line().trim().parse().unwrap(); 33 | 34 | for _ in 0..T { 35 | let age = read_line().trim().parse().unwrap(); 36 | let mut p = Person::new(age); 37 | 38 | p.amIOld(); 39 | 40 | for _ in 0..3 { 41 | p.yearPasses(); 42 | } 43 | 44 | p.amIOld(); 45 | println!(""); 46 | } 47 | } 48 | 49 | fn read_line() -> String { 50 | let mut input = String::new(); 51 | std::io::stdin() 52 | .read_line(&mut input) 53 | .expect("Could not read stdin!"); 54 | return input; 55 | } 56 | -------------------------------------------------------------------------------- /Day4/Solution.swift: -------------------------------------------------------------------------------- 1 | class Person { 2 | var age: Int = 0 3 | 4 | init(initialAge: Int) { 5 | if initialAge > 0 { 6 | self.age = initialAge 7 | } else { 8 | print("Age is not valid, setting age to 0.") 9 | self.age = 0 10 | } 11 | } 12 | 13 | func yearPasses() { 14 | self.age += 1 15 | } 16 | 17 | func amIOld() { 18 | if self.age < 13 { 19 | print("You are young.") 20 | } else if self.age < 18 { 21 | print("You are a teenager.") 22 | } else { 23 | print("You are old.") 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Day4/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | type person struct { 5 | age int 6 | } 7 | 8 | func (p person) NewPerson(initialAge int) person { 9 | //Add some more code to run some checks on initialAge 10 | if (initialAge < 0) { 11 | fmt.Println("Age is not valid, setting age to 0.") 12 | initialAge = 0 13 | } 14 | p.age = initialAge 15 | return p 16 | } 17 | 18 | func (p person) amIOld() { 19 | //Do some computation in here and print out the correct statement to the console 20 | if(p.age <13 ) { 21 | fmt.Println("You are young.") 22 | 23 | } else if (p.age >=13 && p.age <18) { 24 | fmt.Println("You are a teenager.") 25 | 26 | } else { 27 | fmt.Println("You are old.") 28 | 29 | } 30 | } 31 | 32 | func (p person) yearPasses() person { 33 | //Increment the age of the person in here 34 | p.age += 1 35 | return p 36 | } 37 | 38 | func main() { 39 | var T,age int 40 | 41 | fmt.Scan(&T) 42 | 43 | for i := 0; i < T; i++ { 44 | fmt.Scan(&age) 45 | p := person{age: age} 46 | p = p.NewPerson(age) 47 | p.amIOld() 48 | for j := 0; j < 3; j++ { 49 | p = p.yearPasses() 50 | } 51 | p.amIOld() 52 | fmt.Println() 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Day5/Solution.c: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int N; 3 | scanf("%d",&N); 4 | for(int i=1;i<=10;i++){ 5 | printf("%d x %d = %d\n", N, i, (N*i)); 6 | } 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Day5/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int N; 3 | cin >> N; 4 | 5 | for(int i=1;i<=10;i++){ 6 | cout << N << " x " << i << " = " << (N*i) << endl; 7 | } 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Day5/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | Scanner in = new Scanner(System.in); 5 | int N = in.nextInt(); 6 | for(int i=1;i<=10;i++){ 7 | System.out.println(N +" x "+i+" = "+(N*i)); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Day5/Solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | 6 | N = int(input().strip()) 7 | for i in range(1, 11): 8 | print(str(N) +" x " + str(i) + " = " + str(N*i)) 9 | -------------------------------------------------------------------------------- /Day5/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() -> Result<(), Box> { 4 | let mut input = String::new(); 5 | io::stdin().read_line(&mut input)?; 6 | let n: i32 = input.parse()?; 7 | for i in 1..=10 { 8 | println!("{} x {} = {}", n, i, n * i); 9 | } 10 | Ok(()) 11 | } 12 | -------------------------------------------------------------------------------- /Day5/Solution.swift: -------------------------------------------------------------------------------- 1 | let n = Int(readLine()!)! 2 | 3 | for i in 1...10{ 4 | print("\(n) x \(i) = \(n*i)") 5 | } 6 | -------------------------------------------------------------------------------- /Day5/solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | func main() { 5 | var number int 6 | fmt.Scanf("%v", &number) 7 | 8 | for i := 1; i <= 10; i++ { 9 | fmt.Println(number, "x", i, "=", number*i) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Day6/Solution.c: -------------------------------------------------------------------------------- 1 | void printEvenIndexChar(char arr[]){ 2 | int len = strlen(arr); 3 | for (int i = 0;i < len; i++){ 4 | if(i%2 ==0) 5 | printf("%c", arr[i]); 6 | } 7 | 8 | } 9 | 10 | void printOddIndexChar(char arr[]){ 11 | int len = strlen(arr); 12 | for (int i = 0;i < len; i++){ 13 | if(i%2 !=0) 14 | printf("%c", arr[i]); 15 | } 16 | 17 | } 18 | 19 | int main() { 20 | 21 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 22 | char s[10000]; 23 | int t; 24 | scanf("%d",&t); 25 | for (int a0 = 0; a0 < t; a0++){ 26 | scanf("%s", s); 27 | printEvenIndexChar(s); 28 | printf(" "); 29 | printOddIndexChar(s); 30 | printf("\n"); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Day6/Solution.cpp: -------------------------------------------------------------------------------- 1 | void printEvenIndexChar(string s){ 2 | int len = s.length(); 3 | for (int i = 0;i < len; i++){ 4 | if(i%2 ==0) 5 | cout<< s[i]; 6 | } 7 | 8 | } 9 | 10 | void printOddIndexChar(string s){ 11 | int len = s.length(); 12 | for (int i = 0;i < len; i++){ 13 | if(i%2 !=0) 14 | cout << s[i]; 15 | } 16 | 17 | } 18 | 19 | int main() { 20 | 21 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 22 | string s; 23 | int t; 24 | cin >> t; 25 | for (int a0 = 0; a0 < t; a0++){ 26 | cin >> s; 27 | printEvenIndexChar(s); 28 | cout << " "; 29 | printOddIndexChar(s); 30 | cout << endl; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Day6/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "fmt" 7 | "os" 8 | ) 9 | 10 | func transform(line string) string { 11 | var buffer bytes.Buffer; 12 | 13 | for i := 0; i < len(line); i += 2 { 14 | buffer.WriteByte(line[i]) 15 | } 16 | 17 | buffer.WriteString(" ") 18 | 19 | for i := 1; i < len(line); i += 2 { 20 | buffer.WriteByte(line[i]) 21 | } 22 | 23 | return buffer.String() 24 | } 25 | 26 | func main() { 27 | var numCases int 28 | fmt.Scanf("%d", &numCases) 29 | 30 | scanner := bufio.NewScanner(os.Stdin) 31 | 32 | for i := 0; i < numCases; i++ { 33 | if scanner.Scan() { 34 | fmt.Println(transform(scanner.Text())) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Day6/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | Scanner scanner = new Scanner(System.in); 4 | String S; 5 | int t; 6 | public int setTestCase(){ 7 | t = scanner.nextInt(); 8 | scanner.nextLine(); 9 | return t; 10 | } 11 | public void setString(){ 12 | 13 | S = scanner.nextLine(); 14 | } 15 | public void printEvenIndexChar(){ 16 | int len = S.length(); 17 | for (int i = 0;i < len; i++){ 18 | if(i%2 ==0) 19 | System.out.print(S.charAt(i)); 20 | } 21 | 22 | } 23 | 24 | public void printOddIndexChar(){ 25 | int len = S.length(); 26 | for (int i = 0;i < len; i++){ 27 | if(i%2 !=0) 28 | System.out.print(S.charAt(i)); 29 | } 30 | 31 | } 32 | 33 | 34 | public static void main(String[] args) { 35 | 36 | Solution num = new Solution(); 37 | int T = num.setTestCase(); 38 | 39 | for(int a0=0;a0 Result<(), Box> { 4 | let mut n_tests = String::new(); 5 | io::stdin().read_line(&mut n_tests)?; 6 | let n: i32 = n_tests.trim().parse()?; 7 | for _ in 0..n { 8 | let mut line = String::new(); 9 | io::stdin().read_line(&mut line)?; 10 | let even: String = line 11 | .trim() 12 | .chars() 13 | .enumerate() 14 | .filter(|(i, _)| i % 2 == 0) 15 | .map(|(_, ch)| ch) 16 | .collect(); 17 | let odd: String = line 18 | .trim() 19 | .chars() 20 | .enumerate() 21 | .filter(|(i, _)| i % 2 != 0) 22 | .map(|(_, ch)| ch) 23 | .collect(); 24 | println!("{} {}", even, odd); 25 | } 26 | Ok(()) 27 | } 28 | -------------------------------------------------------------------------------- /Day6/Solution.swift: -------------------------------------------------------------------------------- 1 | func printEvenIndexChars(arr: [String]) -> String { 2 | var evens = "" 3 | for i in 0...arr.count-1 { 4 | if(i % 2 == 0) { 5 | evens += arr[i] 6 | } 7 | } 8 | return evens 9 | } 10 | 11 | func printOddIndexChars(arr: [String]) -> String { 12 | var odds = "" 13 | for i in 0...arr.count-1 { 14 | if(i % 2 == 1) { 15 | odds += arr[i] 16 | } 17 | } 18 | return odds 19 | } 20 | 21 | let num: Int? = Int(readLine()!) 22 | 23 | for i in 0...num!-1 { 24 | let input = readLine()! 25 | 26 | var arr = [String]() 27 | for char in input { 28 | arr.append(String(char)) 29 | } 30 | 31 | print(printEvenIndexChars(arr: arr) + " " + printOddIndexChars(arr: arr)) 32 | } 33 | -------------------------------------------------------------------------------- /Day7/Solution.c: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int n; 3 | scanf("%d",&n); 4 | int *arr = malloc(sizeof(int) * n); 5 | for(int arr_i = 0; arr_i < n; arr_i++){ 6 | scanf("%d",&arr[arr_i]); 7 | } 8 | for(int i=n-1;i >= 0 ; i--){ 9 | printf("%d ",arr[i]); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Day7/Solution.cpp: -------------------------------------------------------------------------------- 1 | 2 | int main(){ 3 | int n; 4 | cin >> n; 5 | vector arr(n); 6 | for(int arr_i = 0;arr_i < n;arr_i++){ 7 | cin >> arr[arr_i]; 8 | } 9 | 10 | for(int i = n-1; i>=0; i--){ 11 | cout << arr[i] << " "; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Day7/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | import ( 3 | "fmt" 4 | ) 5 | 6 | func main() { 7 | var size int; 8 | fmt.Scanf("%d", &size) 9 | 10 | var array = make([]int, size) 11 | for i := 0; i < size; i++ { 12 | fmt.Scanf("%d", &array[i]) 13 | } 14 | 15 | for i := size; i > 0; i-- { 16 | fmt.Printf("%d ", array[i-1]) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day7/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | Scanner in = new Scanner(System.in); 5 | int n = in.nextInt(); 6 | int[] arr = new int[n]; 7 | for(int i=0; i < n; i++){ 8 | arr[i] = in.nextInt(); 9 | } 10 | in.close(); 11 | for(int i=n-1;i >= 0 ; i--){ 12 | System.out.print(arr[i]+ " "); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Day7/Solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | 6 | n = int(input().strip()) 7 | arr = list(map(int,input().strip().split(' '))) 8 | ans = "" 9 | for i in range(len(arr)-1 , -1, -1): 10 | ans += str(arr[i]) + " " 11 | 12 | print(ans) 13 | 14 | -------------------------------------------------------------------------------- /Day7/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | guard let n = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!) 4 | else { fatalError("Bad input") } 5 | 6 | guard let arrTemp = readLine() else { fatalError("Bad input") } 7 | let arr: [Int] = arrTemp.split(separator: " ").map { 8 | if let arrItem = Int($0.trimmingCharacters(in: .whitespacesAndNewlines)) { 9 | return arrItem 10 | } else { fatalError("Bad input") } 11 | } 12 | 13 | guard arr.count == n else { fatalError("Bad input") } 14 | 15 | for i in (0...n-1).reversed() { 16 | print("\(arr[i]) ", terminator: "") 17 | } 18 | -------------------------------------------------------------------------------- /Day8/Solution.cpp: -------------------------------------------------------------------------------- 1 | int main() { 2 | int n; 3 | cin >>n; 4 | map phonebook; 5 | string name, id; 6 | for (int i=0; i>name >> id; 8 | phonebook[name] = id; 9 | } 10 | while(cin >> name) { 11 | if (phonebook.find(name) != phonebook.end()) { 12 | cout << name << "=" << phonebook.find(name)->second << endl; 13 | } else { 14 | cout << "Not found" << endl; 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Day8/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | func main() { 12 | in := bufio.NewScanner(os.Stdin) 13 | in.Scan() 14 | n, _ := strconv.Atoi(in.Text()) 15 | 16 | phoneBook := make(map[string]int) 17 | 18 | for i := 0; i < n; i++ { 19 | in.Scan() 20 | input := in.Text() 21 | values := strings.Split(input, " ") 22 | name := values[0] 23 | phone, _ := strconv.Atoi(values[1]) 24 | 25 | phoneBook[name] = phone 26 | } 27 | 28 | for { 29 | in.Scan() 30 | key := in.Text() 31 | if key == "" { 32 | break 33 | } 34 | 35 | if value, ok := phoneBook[key]; ok { 36 | fmt.Printf("%s=%d\n", key, value) 37 | } else { 38 | fmt.Println("Not found") 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Day8/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public static void main(String []argh){ 3 | Scanner in = new Scanner(System.in); 4 | int n = in.nextInt(); 5 | Map phoneBook = new HashMap(); 6 | for(int i = 0; i < n; i++){ 7 | String name = in.next(); 8 | int phone = in.nextInt(); 9 | phoneBook.put(name, phone); 10 | 11 | } 12 | while(in.hasNext()){ 13 | String s = in.next(); 14 | if(phoneBook.containsKey(s)) 15 | System.out.println(s + "=" + phoneBook.get(s)); 16 | else 17 | System.out.println("Not found"); 18 | 19 | 20 | } 21 | in.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Day8/Solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | inputList=[] 3 | 4 | for line in sys.stdin: 5 | inputList.append(line) 6 | 7 | n = int(inputList[0]) 8 | entries = inputList[1:n+1] 9 | queries = inputList[n+1:] 10 | 11 | phoneBook = {} 12 | 13 | for entry in entries: 14 | name, id = entry.split() 15 | phoneBook[name] = id 16 | 17 | for query in queries: 18 | stripQuery = query.rstrip() #Eliminates the newline character 19 | if stripQuery in phoneBook: 20 | print(stripQuery + "=" + str(phoneBook[stripQuery])) 21 | else: 22 | print("Not found") 23 | -------------------------------------------------------------------------------- /Day8/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use std::io; 3 | use std::io::BufRead; 4 | 5 | fn main() -> Result<(), Box> { 6 | let mut phonebook = HashMap::new(); 7 | let mut n_numbers = String::new(); 8 | 9 | io::stdin().read_line(&mut n_numbers)?; 10 | let n: i32 = n_numbers.trim().parse()?; 11 | for _ in 0..n { 12 | let mut line = String::new(); 13 | io::stdin().read_line(&mut line)?; 14 | let mut words = line.split_whitespace(); 15 | let name = words.next().unwrap().to_string(); 16 | let number = words.next().unwrap().to_string(); 17 | phonebook.insert(name.clone(), number.clone()); 18 | } 19 | for query in io::stdin().lock().lines() { 20 | let name = query.unwrap(); 21 | let result = match phonebook.get(&name) { 22 | Some(number) => format!("{}={}", name, number), 23 | None => "Not found".to_string(), 24 | }; 25 | println!("{}", result); 26 | } 27 | Ok(()) 28 | } 29 | -------------------------------------------------------------------------------- /Day8/Solution.swift: -------------------------------------------------------------------------------- 1 | // Enter your code here. Read input from STDIN. Print output to STDOUT 2 | 3 | var phoneBook: [String:String] = [:] 4 | let n = Int(readLine()!)! 5 | 6 | for i in 1...n { 7 | let currentLine = readLine()!.split(separator: " ") 8 | phoneBook[String(currentLine[0])] = String(currentLine[1]) 9 | } 10 | 11 | while(1==1) { 12 | if let query = readLine() { 13 | if(phoneBook[query] != nil) { 14 | print(query + "=" + phoneBook[query]!) 15 | } else { 16 | print("Not found") 17 | } 18 | } else { 19 | break 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Day9/Solution.c: -------------------------------------------------------------------------------- 1 | int factorial(int n){ 2 | if(n<=1) 3 | return 1; 4 | else 5 | return n*factorial(n-1); 6 | } 7 | 8 | int main() { 9 | int n; 10 | scanf("%d", &n); 11 | printf("%d", factorial(n)); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Day9/Solution.cpp: -------------------------------------------------------------------------------- 1 | int factorial(int n){ 2 | if(n<=1) 3 | return 1; 4 | else 5 | return n*factorial(n-1); 6 | } 7 | 8 | int main() { 9 | int n; 10 | cin >> n; 11 | cout << factorial(n); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Day9/Solution.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | var n int 5 | 6 | func factorial(n int) int{ 7 | if(n<=1){ 8 | return 1 9 | } else{ 10 | return n*factorial(n-1) 11 | } 12 | } 13 | 14 | func main(){ 15 | fmt.Scan(&n) 16 | fmt.Print(factorial(n)) 17 | } 18 | -------------------------------------------------------------------------------- /Day9/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public static int factorial(int n){ 3 | if(n<=1) 4 | return 1; 5 | else 6 | return n*factorial(n-1); 7 | } 8 | public static void main(String[] args) { 9 | /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ 10 | Scanner sc = new Scanner(System.in); 11 | int N = sc.nextInt(); 12 | System.out.println(factorial(N)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Day9/Solution.py: -------------------------------------------------------------------------------- 1 | def factorial(n): 2 | if n<=1: 3 | return 1 4 | else: 5 | return n*factorial(n-1) 6 | 7 | n = int(input()) 8 | print(factorial(n)) 9 | -------------------------------------------------------------------------------- /Day9/Solution.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | fn main() { 4 | let mut input = String::new(); 5 | match io::stdin().read_line(&mut input){ 6 | Ok(_) => { 7 | match input.trim().parse::() { 8 | Ok(number) => { 9 | println!("{0}", factorial(number)); 10 | } 11 | Err(error) => { 12 | panic!("{:?}", error); 13 | } 14 | } 15 | }, 16 | Err(error) => { 17 | panic!("{:?}", error); 18 | } 19 | } 20 | } 21 | 22 | fn factorial(n: i32) -> i32{ 23 | if n == 1 { 24 | return 1; 25 | } 26 | n * factorial(n-1) 27 | } -------------------------------------------------------------------------------- /Day9/Solution.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // Complete the factorial function below. 4 | func factorial(n: Int) -> Int { 5 | if(n==1) { 6 | return n 7 | } else { 8 | return(n * factorial(n: n-1)) 9 | } 10 | } 11 | 12 | let stdout = ProcessInfo.processInfo.environment["OUTPUT_PATH"]! 13 | FileManager.default.createFile(atPath: stdout, contents: nil, attributes: nil) 14 | let fileHandle = FileHandle(forWritingAtPath: stdout)! 15 | 16 | guard let n = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!) 17 | else { fatalError("Bad input") } 18 | 19 | let result = factorial(n: n) 20 | 21 | fileHandle.write(String(result).data(using: .utf8)!) 22 | fileHandle.write("\n".data(using: .utf8)!) 23 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Sagar Choudhary 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 30 Days Of Code 2 | 3 | ![open issues](https://img.shields.io/github/issues/sagarchoudhary96/30-Days-Of-Code?color=%2319a249) ![open PR](https://img.shields.io/github/issues-pr-closed/sagarchoudhary96/30-days-of-code?color=%23f25f56) ![license](https://img.shields.io/github/license/sagarchoudhary96/30-days-of-code) ![forks](https://img.shields.io/github/forks/sagarchoudhary96/30-days-of-code?style=social) 4 | 5 | A 30-day video tutorial series for people with no programming experience and want to learn how to code. 6 | 7 | Here are the solutions to all the HackerRank challenge questions For this series. Join [HERE](http://hr.gs/fdeeee) to practice. 8 | 9 | ### The following is the list of problem statements and solutions:- 10 | # 11 | 12 | - **Day0**: [Question](https://www.hackerrank.com/challenges/30-hello-world/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day0)       **Day10**: [Question](https://www.hackerrank.com/challenges/30-binary-numbers/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day10)        13 | **Day20**: [Question](https://www.hackerrank.com/challenges/30-sorting/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day20) 14 | 15 | - **Day1**: [Question](https://www.hackerrank.com/challenges/30-data-types/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day1)       **Day11**: [Question](https://www.hackerrank.com/challenges/30-2d-arrays/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day11)        16 | **Day21**: [Question](https://www.hackerrank.com/challenges/30-generics/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day21) 17 | 18 | - **Day2**: [Question](https://www.hackerrank.com/challenges/30-operators/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day2)       **Day12**: [Question](https://www.hackerrank.com/challenges/30-inheritance/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day12)        19 | **Day22**: [Question](https://www.hackerrank.com/challenges/30-binary-search-trees/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day22) 20 | 21 | - **Day3**: [Question](https://www.hackerrank.com/challenges/30-conditional-statements/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day3)       **Day13**: [Question](https://www.hackerrank.com/challenges/30-abstract-classes/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day13)        22 | **Day23**: [Question](https://www.hackerrank.com/challenges/30-binary-trees/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day23) 23 | 24 | - **Day4**: [Question](https://www.hackerrank.com/challenges/30-class-vs-instance/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day4)       **Day14**: [Question](https://www.hackerrank.com/challenges/30-scope/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day14)        25 | **Day24**: [Question](https://www.hackerrank.com/challenges/30-linked-list-deletion/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day24) 26 | 27 | - **Day5**: [Question](https://www.hackerrank.com/challenges/30-loops/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day5)       **Day15**: [Question](https://www.hackerrank.com/challenges/30-linked-list/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day15)        28 | **Day25**: [Question](https://www.hackerrank.com/challenges/30-running-time-and-complexity/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day25) 29 | 30 | - **Day6**: [Question](https://www.hackerrank.com/challenges/30-review-loop/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day6)       **Day16**: [Question](https://www.hackerrank.com/challenges/30-exceptions-string-to-integer/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day16)        31 | **Day26**: [Question](https://www.hackerrank.com/challenges/30-nested-logic/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day26) 32 | 33 | - **Day7**: [Question](https://www.hackerrank.com/challenges/30-arrays/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day7)       **Day17**: [Question](https://www.hackerrank.com/challenges/30-more-exceptions/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day17)        34 | **Day27**: [Question](https://www.hackerrank.com/challenges/30-testing/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day27) 35 | 36 | - **Day8**: [Question](https://www.hackerrank.com/challenges/30-dictionaries-and-maps/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day8)       **Day18**: [Question](https://www.hackerrank.com/challenges/30-queues-stacks/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day18)        37 | **Day28**: [Question](https://www.hackerrank.com/challenges/30-regex-patterns/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day28) 38 | 39 | - **Day9**: [Question](https://www.hackerrank.com/challenges/30-recursion/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day9)       **Day19**: [Question](https://www.hackerrank.com/challenges/30-interfaces/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day19)        40 | **Day29**: [Question](https://www.hackerrank.com/challenges/30-bitwise-and/problem) [Solutions](https://github.com/sagarchoudhary96/30-Days-Of-Code/tree/master/Day29) 41 | 42 | ## Contributing 43 | 44 | Everyone is welcomed to contribute to this project. You can contribute either by submitting bugs or suggesting improvements by opening an issue on GitHub. please see the [CONTRIBUTING](https://github.com/sagarchoudhary96/30-Days-Of-Code/blob/master/CONTRIBUTING.md) guidelines for more information. 45 | 46 | ## LICENSE 47 | This project is licensed under the [MIT License](https://github.com/sagarchoudhary96/30-Days-Of-Code/blob/master/LICENSE.md). 48 | --------------------------------------------------------------------------------