├── (15 Feb 2022) JS practice Contest ├── JsReverse.js ├── app.js ├── index.html └── style.css ├── (8 Feb 2022) Js Contest - 2 ├── GroceryList.html ├── HotOrCold.html ├── JavascriptPrototypes.js ├── JsErrorHandling.js └── YoutubeLikes.html ├── 1-D Array [In Class] ├── AverageMe.js ├── IncreasingArray.java └── SumAndMean.js ├── 1-D Array [Post Class] ├── AlternateSumproduct.js ├── Buildings.js ├── IsThisRepeated.java ├── ReplaceElement.js └── SimpleArrangement.js ├── 2-D Matrix [In Class] ├── DiagonalSum.js └── MaxSumColumn.js ├── 2-D Matrix ├── BooleanMatrix.java ├── GoodCells.js └── RowWithMaximum1s.js ├── ArrayList and Linked List [Post Class] ├── DeleteTheKthNodeFromTheEnd.java ├── DeletionInDoublyLinkedList.java ├── IntersectionOfTwoLinkedLists.java ├── MergeTwoSortedLinkedLists.java ├── PalindromeList.java ├── PrintTheLinkedList.java └── ReversingADoublyLinkedList.java ├── Control Structures and Loops [Post Class] ├── NewtonSchoolProblem.java ├── PatternPrinting.java └── TriangleRightAngle.java ├── Development Enviornment Setup, Fundamentals of java [In Class] ├── CuboidPerimeter.java └── FocalLengthOfSphericalMirror.java ├── Functions & Recursion [In Class] ├── FactorialRecursion.js ├── PowerFunction.js └── TowerOfHanoi.js ├── Functions & Recursion ├── CandyCrush.java ├── FibonacciNumbers.js ├── NumberOfWays.java ├── SumOfDigits.js └── SumOfProductOfDigitsOfaGivenNumber.js ├── Functions [Post Class] └── HelpSherlock.js ├── Linear Search and Binary Search [In Class] └── SearchingAnElementInASortedArray.java ├── Linear Search and Binary Search [Post Class] ├── MinimumElementInSortedArray.java └── SquareRootOfInteger.js ├── Loops [Post Class] ├── ArmstrongNumber.js └── SingleDigit.js ├── Objected Oriented Programming [In Class] └── ClassesInJava.java ├── Readme.md ├── STL [Post Class] ├── AdditionOfCommonElements.java ├── MaxFreq.java ├── PairSumVector.java ├── RemoveDuplicatesFromArray.java └── SubArrayWithGivenSum.java ├── Simple Array Sorting and its implementation [Post Class] ├── ImplementingBubbleSort.js ├── ImplementingInsertionSort.js ├── ImplementingMergeSort.js ├── SelectionSort.js ├── Shopping.js ├── Sort0s1s2s.js └── bubbleSort(DescendingOrder).js ├── Stack [Post Class] ├── Array implementation of stack.java ├── GreaterIsBetter.java ├── Height Problem.java ├── Infix to Postfix.java ├── Nearest Smaller Element.java ├── Stack Implementation using linked list.java ├── Stack Operations.java └── StockSpanProblem.java └── Strings [Post Class] ├── Anagram.js ├── LongestCommonPrefixInAnArray.js ├── LongestDistinctCharacters.java ├── OddCharacters.js ├── Palindrome.js ├── PangramChecking.js ├── RepeatingCharacter.js ├── Reverse.py ├── StringSum.js └── isPalindrome.js /(15 Feb 2022) JS practice Contest/JsReverse.js: -------------------------------------------------------------------------------- 1 | // num is input number 2 | function reverseNumber(num) { 3 | let reversed = ""; 4 | while (num > 0) { 5 | reversed += num % 10; 6 | num = Math.floor(num / 10); 7 | } 8 | return Number(reversed); 9 | } 10 | -------------------------------------------------------------------------------- /(15 Feb 2022) JS practice Contest/app.js: -------------------------------------------------------------------------------- 1 | const todoContainer = document.querySelector(".todo-list"); 2 | const submitBtn = document.querySelector(".todo-button"); 3 | 4 | submitBtn.addEventListener("click", (e) => { 5 | e.preventDefault(); 6 | let inputEle = document.querySelector(".todo-input"); 7 | let val = inputEle.value; 8 | addList(val); 9 | inputEle.value = null; 10 | }); 11 | 12 | function addList(value) { 13 | const li = document.createElement("li"); 14 | li.innerHTML = ` 15 |

${value}

16 | 17 | `; 18 | todoContainer.appendChild(li); 19 | } 20 | 21 | function removeList(target) { 22 | target.removeEventListener("click", (e) => removeList(e)); 23 | target.parentElement.remove(); 24 | } 25 | 26 | function markCompleted(target) { 27 | let classlist = target.parentElement.firstChild.nextElementSibling.classList; 28 | classlist.contains("textDecoration") 29 | ? classlist.remove("textDecoration") 30 | : classlist.add("textDecoration"); 31 | } 32 | -------------------------------------------------------------------------------- /(15 Feb 2022) JS practice Contest/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | TO Do List 13 | 14 | 15 | 16 |
My Todo list
17 |
18 |
19 | 20 | 21 |
22 |
23 | 24 |
25 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /(15 Feb 2022) JS practice Contest/style.css: -------------------------------------------------------------------------------- 1 | .textDecoration{ 2 | text-decoration: line-through solid rgb(0, 0, 0); 3 | } -------------------------------------------------------------------------------- /(8 Feb 2022) Js Contest - 2/GroceryList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |

Grocery List

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
Sr. No.TitlePrice
1Item-1100
2Item-2200
3Item-32
4Item-41
43 | 44 | 71 | 72 | -------------------------------------------------------------------------------- /(8 Feb 2022) Js Contest - 2/HotOrCold.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

11 | I am learning to generate random number. I will be able to handle randomness in any of my applications that needs 12 | it. Press the button to get a random number. 13 |

14 | 15 | 16 |

17 | 28 | 29 | -------------------------------------------------------------------------------- /(8 Feb 2022) Js Contest - 2/JavascriptPrototypes.js: -------------------------------------------------------------------------------- 1 | Array.prototype.includesOneof = function (arr) { 2 | if (arr.length === 0) return false; 3 | if (typeof arr[0] === "object" || Array.isArray(arr[0])) { 4 | let givenArray = arr.map((elem) => JSON.stringify(elem)); 5 | let appliedOnArray = this.map((elem) => JSON.stringify(elem)); 6 | let removedDuplicates = new Set([...givenArray, ...appliedOnArray]); 7 | if (arr.length + this.length === removedDuplicates.size) return false; 8 | else return true; 9 | } 10 | for (let i = 0; i < arr.length; i++) { 11 | if (this.includes(arr[i])) return true; 12 | } 13 | return false; 14 | }; 15 | -------------------------------------------------------------------------------- /(8 Feb 2022) Js Contest - 2/JsErrorHandling.js: -------------------------------------------------------------------------------- 1 | function evalString() { 2 | let str = document.getElementById("input1").value; 3 | try { 4 | //write your code here 5 | // if (/^[\+\-\*\/]/.test(str)) 6 | // throw new SyntaxError( 7 | // "Expression should not start with invalid operator" 8 | // ); 9 | // else if (/[\+\-\*\/]$/.test(str)) 10 | // throw new SyntaxError( 11 | // "Expression should not end with invalid operator" 12 | // ); 13 | // else if (/[a-zA-z]/.test(str)) { 14 | // throw new OutOfRangeError(); 15 | // } 16 | // else if (/[\+\-\*\/]?= [\+\-\*\/]/) { 17 | // throw new InvalidExprError(); 18 | // } 19 | // alert("passed"); 20 | } catch (e) { 21 | alert("failed " + e.name + " " + e.message); 22 | if (window.Cypress) { 23 | throw e; 24 | } 25 | } 26 | } 27 | 28 | class OutOfRangeError extends Error { 29 | constructor() { 30 | super(); 31 | this.name = "OutOfRangeError"; 32 | this.message = 33 | "Expression should only consist of integers and +-/* characters and not 'a'"; 34 | } 35 | } 36 | class InvalidExprError extends Error { 37 | constructor() { 38 | super(); 39 | this.name = "InvalidExprError"; 40 | this.message = 41 | "Expression should not have an invalid combination of expression"; 42 | } 43 | } 44 | 45 | if (window.Cypress) { 46 | window.OutOfRangeError = OutOfRangeError; 47 | window.InvalidExprError = InvalidExprError; 48 | } 49 | -------------------------------------------------------------------------------- /(8 Feb 2022) Js Contest - 2/YoutubeLikes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

0

11 | 12 | 13 | 31 | 32 | -------------------------------------------------------------------------------- /1-D Array [In Class]/AverageMe.js: -------------------------------------------------------------------------------- 1 | function averageMe(sizeOfArray, array) { 2 | return Math.floor( 3 | array.reduce((sum, height) => (sum += height), 0) / sizeOfArray 4 | ); 5 | } 6 | -------------------------------------------------------------------------------- /1-D Array [In Class]/IncreasingArray.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | 10 | Scanner sc = new Scanner(System.in); 11 | int n; 12 | n = sc.nextInt(); 13 | int[] arr = new int[n]; 14 | for (int i = 0; i < n; i++) 15 | arr[i] = sc.nextInt(); 16 | 17 | int count = 2; 18 | boolean flag = false; 19 | 20 | for (int i = 1; i < arr.length; i++) { 21 | while (count <= arr[i] && arr[i] % count != 0) { 22 | count++; 23 | } 24 | if (arr[i] < count) { 25 | System.out.println("NO"); 26 | flag = true; 27 | break; 28 | } 29 | count++; 30 | } 31 | 32 | if (flag == false) { 33 | System.out.println("YES"); 34 | } 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /1-D Array [In Class]/SumAndMean.js: -------------------------------------------------------------------------------- 1 | // arr is the array of numbers, n is the number of elements 2 | function sumAndMean(arr, n) { 3 | const sum = arr.reduce((sum, num) => (sum += num), 0); 4 | return [sum, Math.floor(sum / n)]; 5 | } 6 | -------------------------------------------------------------------------------- /1-D Array [Post Class]/AlternateSumproduct.js: -------------------------------------------------------------------------------- 1 | // arr is the array of numbers, n is number of elements 2 | function altSumProduct(arr, n) { 3 | // write code here 4 | // console.log the output in a single line,like example 5 | let sum = 0; 6 | let product = 1; 7 | for (let i = 0; i < n; i++) 8 | i % 2 == 0 ? (product *= arr[i]) : (sum += arr[i]); 9 | console.log(sum, product); 10 | } 11 | -------------------------------------------------------------------------------- /1-D Array [Post Class]/Buildings.js: -------------------------------------------------------------------------------- 1 | function numberOfRoofs(arr) { 2 | // Your code here 3 | let count = 1; 4 | let max = arr[0]; 5 | for (let i = 1; i < arr.length; i++) { 6 | if (arr[i] > max) { 7 | count++; 8 | max = arr[i]; 9 | } 10 | } 11 | return count; 12 | } 13 | -------------------------------------------------------------------------------- /1-D Array [Post Class]/IsThisRepeated.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner scan = new Scanner(System.in); 10 | int n = scan.nextInt(); 11 | int[] arr = new int[n]; 12 | for (int i = 0; i < n; i++) 13 | arr[i] = scan.nextInt(); 14 | boolean flag = false; 15 | for (int i = 0; i < n - 2; i++) { 16 | if (arr[i] == arr[i + 1] && arr[i] == arr[i + 2]) { 17 | System.out.println("Yes"); 18 | flag = true; 19 | break; 20 | } 21 | } 22 | if (!flag) 23 | System.out.println("No"); 24 | } 25 | } -------------------------------------------------------------------------------- /1-D Array [Post Class]/ReplaceElement.js: -------------------------------------------------------------------------------- 1 | // arr is the array of numbers, n is the number of elements 2 | function replaceArray(arr, n) { 3 | // write code here 4 | // do not console.log 5 | // return the new array 6 | let res = []; 7 | res[0] = arr[0] * arr[1]; 8 | for (let i = 1; i < n - 1; i++) res[i] = arr[i - 1] * arr[i + 1]; 9 | res[res.length] = arr[n - 1] * arr[n - 2]; 10 | return res; 11 | } 12 | -------------------------------------------------------------------------------- /1-D Array [Post Class]/SimpleArrangement.js: -------------------------------------------------------------------------------- 1 | // n is size of array, arr is the array 2 | function simpleArrangement(n, arr) { 3 | let res = []; 4 | for (let i = 0; i < n; i++) res[i] = arr[arr[i]]; 5 | return res; 6 | } 7 | -------------------------------------------------------------------------------- /2-D Matrix [In Class]/DiagonalSum.js: -------------------------------------------------------------------------------- 1 | // mat is the matrix/ 2d array 2 | // the dimensions of array are n * n 3 | function diagonalSum(mat, n) { 4 | // write code here 5 | // console.log the answer as in example 6 | let primarySum = 0; 7 | let secondarySum = 0; 8 | for (let i = 0; i < n; i++) { 9 | primarySum += mat[i][i]; 10 | secondarySum += mat[i][n - i - 1]; 11 | } 12 | console.log(primarySum, secondarySum); 13 | } 14 | -------------------------------------------------------------------------------- /2-D Matrix [In Class]/MaxSumColumn.js: -------------------------------------------------------------------------------- 1 | // mat is the matrix/ 2d array 2 | // the dimensions of array are:- a rows, b columns 3 | function colMaxSum(mat, a, b) { 4 | // write code here 5 | // do not console.log 6 | // return the answer as a number 7 | 8 | let idx = -1; 9 | 10 | // Variable to store max sum 11 | let maxSum = Number.MIN_VALUE; 12 | 13 | // Traverse matrix column wise 14 | for (let i = 0; i < b; i++) { 15 | let sum = 0; 16 | 17 | // calculate sum of column 18 | for (let j = 0; j < a; j++) { 19 | sum += mat[j][i]; 20 | } 21 | 22 | // Update maxSum if it is 23 | // less than current sum 24 | if (sum > maxSum) { 25 | maxSum = sum; 26 | 27 | // store index 28 | idx = i; 29 | } 30 | } 31 | 32 | let res; 33 | 34 | res = [idx, maxSum]; 35 | 36 | // return result 37 | return maxSum; 38 | } 39 | -------------------------------------------------------------------------------- /2-D Matrix/BooleanMatrix.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Main { 3 | public static void main (String[] args) { 4 | // Your code here 5 | Scanner scan = new Scanner(System.in); 6 | int t = scan.nextInt(); 7 | while(t>0){ 8 | int r = scan.nextInt(); 9 | int c = scan.nextInt(); 10 | int[][] m =new int[r][c]; 11 | for(int i=0;i maxOnes) { 12 | maxOnes = ones; 13 | idx = i; 14 | } 15 | } 16 | return idx; 17 | } 18 | -------------------------------------------------------------------------------- /ArrayList and Linked List [Post Class]/DeleteTheKthNodeFromTheEnd.java: -------------------------------------------------------------------------------- 1 | /* 2 | class Node { 3 | Node next; 4 | int val; 5 | 6 | Node(int val) { 7 | this.val = val; 8 | next = null; 9 | } 10 | } 11 | */ 12 | 13 | public static Node deleteElement(Node head,int k) { 14 | //enter your code here 15 | Node first = head; 16 | Node second = head; 17 | for (int i = 0; i < k; i++) { 18 | if (second.next == null) { 19 | if (i == k - 1) 20 | head = head.next; 21 | return head; 22 | } 23 | second = second.next; 24 | } 25 | while (second.next != null) { 26 | first = first.next; 27 | second = second.next; 28 | } 29 | first.next = first.next.next; 30 | return head; 31 | } -------------------------------------------------------------------------------- /ArrayList and Linked List [Post Class]/DeletionInDoublyLinkedList.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | class Node { 4 | Node next; 5 | Node prev; 6 | int val; 7 | 8 | Node(int val) { 9 | this.val = val; 10 | next = null; 11 | prev = null; 12 | } 13 | } 14 | */ 15 | public static Node deleteElement(Node head,int k) { 16 | //enter your code here 17 | Node rev = head; 18 | while(rev.next != null) rev = rev.next; 19 | 20 | for(int i = 1; i < k; i++) rev = rev.prev; 21 | if(rev.prev == null) 22 | return rev.next; 23 | rev.prev.next = rev.next; 24 | return head; 25 | } -------------------------------------------------------------------------------- /ArrayList and Linked List [Post Class]/IntersectionOfTwoLinkedLists.java: -------------------------------------------------------------------------------- 1 | public static Node intersection(Node head1,Node head2){ 2 | //Enter your code here 3 | 4 | int l1 = getLength(head1); 5 | int l2 = getLength(head2); 6 | 7 | if(l1>l2){ 8 | int diff = l1-l2; 9 | while(diff>0){ 10 | head1 = head1.next; 11 | diff--; 12 | } 13 | } 14 | else{ 15 | int diff = l2-l1; 16 | while(diff>0){ 17 | head2 = head2.next; 18 | diff--; 19 | } 20 | } 21 | while(head1 != null && head2 != null){ 22 | if(head1==head2){ 23 | return head1; 24 | } 25 | else{ 26 | head1=head1.next; 27 | head2=head2.next; 28 | } 29 | } 30 | return head1; 31 | } 32 | 33 | public static int getLength(Node head){ 34 | int length=0; 35 | while(head != null){ 36 | length++; 37 | head =head.next; 38 | } 39 | return length; 40 | } -------------------------------------------------------------------------------- /ArrayList and Linked List [Post Class]/MergeTwoSortedLinkedLists.java: -------------------------------------------------------------------------------- 1 | /* 2 | class Node { 3 | Node next; 4 | int val; 5 | 6 | Node(int val) { 7 | this.val = val; 8 | next = null; 9 | } 10 | } 11 | */ 12 | /* 13 | below function is used to insert nodes in the linked list 14 | public static Node insert111(Node head, int val) { 15 | if(head == null) { 16 | return new Node(val); 17 | } else { 18 | Node cur; 19 | cur = insert111(head.next, val); 20 | head.next = cur; 21 | return head; 22 | } 23 | } 24 | 25 | */ 26 | public static Node Merge (Node head1, Node head2){ 27 | //Enter your code here 28 | if(head1 == null) return head2; 29 | if(head2 == null) return head1; 30 | 31 | if(head1.val < head2.val){ 32 | head1.next = Merge(head1.next, head2); 33 | return head1; 34 | } 35 | head2.next = Merge(head1, head2.next); 36 | return head2; 37 | } -------------------------------------------------------------------------------- /ArrayList and Linked List [Post Class]/PalindromeList.java: -------------------------------------------------------------------------------- 1 | /* 2 | class Node { 3 | Node next; 4 | int val; 5 | 6 | Node(int val) { 7 | this.val = val; 8 | next = null; 9 | } 10 | } 11 | */ 12 | public static boolean IsPalindrome(Node head) { 13 | //enter your code here 14 | Stack stk = new Stack<>(); 15 | Node temp = head; 16 | while(temp != null){ 17 | stk.push(temp.val); 18 | temp = temp.next; 19 | } 20 | while(head != null){ 21 | if(head.val != stk.pop()) return false; 22 | head = head.next; 23 | } 24 | return true; 25 | } -------------------------------------------------------------------------------- /ArrayList and Linked List [Post Class]/PrintTheLinkedList.java: -------------------------------------------------------------------------------- 1 | /* 2 | class Node { 3 | Node next; 4 | int val; 5 | 6 | Node(int val) { 7 | this.val = val; 8 | next = null; 9 | } 10 | } 11 | */ 12 | public static void printList(Node head) { 13 | while(head != null){ 14 | System.out.print(head.val + " "); 15 | head = head.next; 16 | } 17 | } -------------------------------------------------------------------------------- /ArrayList and Linked List [Post Class]/ReversingADoublyLinkedList.java: -------------------------------------------------------------------------------- 1 | /* 2 | class Node { 3 | Node next; 4 | Node prev; 5 | int val; 6 | 7 | Node(int val) { 8 | this.val = val; 9 | next = null; 10 | prev = null; 11 | } 12 | } 13 | */ 14 | public static Node Reverse(Node head) { 15 | //complete this function 16 | Node temp = head; 17 | while(temp.next != null){ 18 | Node tem = temp.next; 19 | temp.next = temp.prev; 20 | temp.prev = tem; 21 | temp = tem; 22 | } 23 | Node tem = temp.next; 24 | temp.next = temp.prev; 25 | temp.prev = tem; 26 | return temp; 27 | } -------------------------------------------------------------------------------- /Control Structures and Loops [Post Class]/NewtonSchoolProblem.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner scan = new Scanner(System.in); 10 | int n = scan.nextInt(); 11 | for (int i = 1; i <= n; i++) { 12 | if (i % 3 == 0 && i % 5 == 0) 13 | System.out.print("NewtonSchool "); 14 | else if (i % 3 == 0) 15 | System.out.print("Newton "); 16 | else if (i % 5 == 0) 17 | System.out.print("School "); 18 | else 19 | System.out.print(i + " "); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Control Structures and Loops [Post Class]/PatternPrinting.java: -------------------------------------------------------------------------------- 1 | static void pattern(int n){ 2 | //enter your code here 3 | for(int i = 1; i <= n; i++){ 4 | for(int j = 1; j <= i; j++) 5 | System.out.print(j + " "); 6 | System.out.println(); 7 | } 8 | } -------------------------------------------------------------------------------- /Control Structures and Loops [Post Class]/TriangleRightAngle.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | for (int i = 0; i < 5; i++) { 10 | for (int j = 0; j <= i; j++) 11 | System.out.print("* "); 12 | System.out.println(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Development Enviornment Setup, Fundamentals of java [In Class]/CuboidPerimeter.java: -------------------------------------------------------------------------------- 1 | static int Perimeter(int L, int B, int H){ 2 | return 4*(L+B+H); 3 | } -------------------------------------------------------------------------------- /Development Enviornment Setup, Fundamentals of java [In Class]/FocalLengthOfSphericalMirror.java: -------------------------------------------------------------------------------- 1 | static int focal_length(int R, char Mirror){ 2 | //Enter your code here 3 | if(Mirror == '(') return R / 2; 4 | else return (R % 2 == 0) ? -R/2 : -((R/2) + 1); 5 | } -------------------------------------------------------------------------------- /Functions & Recursion [In Class]/FactorialRecursion.js: -------------------------------------------------------------------------------- 1 | // n is the input number 2 | function factorial(n) { 3 | if (n < 2) return 1; 4 | return n * factorial(n - 1); 5 | } 6 | -------------------------------------------------------------------------------- /Functions & Recursion [In Class]/PowerFunction.js: -------------------------------------------------------------------------------- 1 | // X and Y are numbers 2 | // ignore number of testcases variable 3 | function pow(X, Y) { 4 | console.log(helper(X, Y).toFixed(2)); 5 | } 6 | 7 | function helper(X, Y) { 8 | if (Y === 0) return 1; 9 | if (Y < 0) { 10 | X = 1 / X; 11 | Y *= -1; 12 | } 13 | let temp; 14 | temp = helper(X, parseInt(Y / 2)); 15 | if (Y % 2 === 0) return temp * temp; 16 | return X * temp * temp; 17 | } 18 | -------------------------------------------------------------------------------- /Functions & Recursion [In Class]/TowerOfHanoi.js: -------------------------------------------------------------------------------- 1 | // n is the number of disks 2 | function towerOfHanoiSequence(n, a = "A", b = "B", c = "C") { 3 | if (n < 1) return; 4 | towerOfHanoiSequence(n - 1, a, c, b); 5 | console.log(`${n}:${a}->${c}`); 6 | towerOfHanoiSequence(n - 1, b, a, c); 7 | } 8 | -------------------------------------------------------------------------------- /Functions & Recursion/CandyCrush.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner scan = new Scanner(System.in); 10 | int testcase = scan.nextInt(); 11 | while (testcase > 0) { 12 | long n = scan.nextLong(); 13 | System.out.println(calculate(n)); 14 | testcase--; 15 | } 16 | } 17 | 18 | public static long calculate(long n) { 19 | if (n == 0) 20 | return 0; 21 | else { 22 | long groups = (n - 1) / 3 + 1; 23 | return groups * groups + calculate(n - groups); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Functions & Recursion/FibonacciNumbers.js: -------------------------------------------------------------------------------- 1 | // n is the input number 2 | function fibonacci(n) { 3 | let t1 = 0; 4 | let t2 = 1; 5 | let tn = 0; 6 | if (n < 1) return t1; 7 | if (n < 2) return t2; 8 | for (let i = 1; i < n; i++) { 9 | tn = t1 + t2; 10 | t1 = t2; 11 | t2 = tn; 12 | } 13 | return tn; 14 | } 15 | -------------------------------------------------------------------------------- /Functions & Recursion/NumberOfWays.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static int count = 0; 8 | 9 | public static void sum(int x, int j) { 10 | if (x == 0) { 11 | count++; 12 | } 13 | if (x < j) { 14 | return; 15 | } else { 16 | for (int i = j; i <= x; i++) { 17 | x = x - i; 18 | sum(x, i + 1); 19 | x = x + i; 20 | } 21 | } 22 | } 23 | 24 | public static void main(String[] args) { 25 | Scanner sc = new Scanner(System.in); 26 | int t = sc.nextInt(); 27 | while (t-- > 0) { 28 | int n = sc.nextInt(); 29 | if (n < 1) { 30 | System.out.println(0); 31 | continue; 32 | } 33 | sum(n, 1); 34 | System.out.println(count); 35 | count = 0; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Functions & Recursion/SumOfDigits.js: -------------------------------------------------------------------------------- 1 | // n is the input number 2 | function recSum(n) { 3 | if (n <= 0) return 0; 4 | return (n % 10) + recSum(Math.floor(n / 10)); 5 | } 6 | -------------------------------------------------------------------------------- /Functions & Recursion/SumOfProductOfDigitsOfaGivenNumber.js: -------------------------------------------------------------------------------- 1 | function sumOfProductOfDigits(n1, n2) { 2 | if (n1 === 0 && n2 === 0) return 0; 3 | const sum = (n1 % 10) * (n2 % 10); 4 | n1 = Math.floor(n1 / 10); 5 | n2 = Math.floor(n2 / 10); 6 | return sum + sumOfProductOfDigits(n1, n2); 7 | } 8 | -------------------------------------------------------------------------------- /Functions [Post Class]/HelpSherlock.js: -------------------------------------------------------------------------------- 1 | function Help(n, m) { 2 | return n % m === 0 ? 1 : 0; 3 | } 4 | -------------------------------------------------------------------------------- /Linear Search and Binary Search [In Class]/SearchingAnElementInASortedArray.java: -------------------------------------------------------------------------------- 1 | static int isPresent(long arr[], int n, long k) 2 | { 3 | // Your code here 4 | int start = 0; 5 | int end = n - 1; 6 | 7 | while (start <= end) { 8 | int middle = (start + end) / 2; 9 | 10 | if (arr[middle] == k) { 11 | // found the k 12 | return 1; 13 | } else if (arr[middle] < k) { 14 | // continue searching to the right 15 | start = middle + 1; 16 | } else { 17 | // search searching to the left 18 | end = middle - 1; 19 | } 20 | } 21 | // k wasn't found 22 | return -1; 23 | } -------------------------------------------------------------------------------- /Linear Search and Binary Search [Post Class]/MinimumElementInSortedArray.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner sc = new Scanner(System.in); 10 | int testCases = sc.nextInt(); 11 | while (testCases > 0) { 12 | int n = sc.nextInt(); 13 | int a = sc.nextInt(); 14 | int min = a; 15 | for (int i = 1; i < n; i++) { 16 | a = sc.nextInt(); 17 | if (a < min) 18 | min = a; 19 | } 20 | System.out.println(min); 21 | testCases--; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Linear Search and Binary Search [Post Class]/SquareRootOfInteger.js: -------------------------------------------------------------------------------- 1 | // n is the input number 2 | function sqrt(n) { 3 | if (n === 0 || n === 1) return n; 4 | let result = 1; 5 | let i = 1; 6 | while (result <= n) { 7 | i++; 8 | result = i * i; 9 | } 10 | return i - 1; 11 | } 12 | -------------------------------------------------------------------------------- /Loops [Post Class]/ArmstrongNumber.js: -------------------------------------------------------------------------------- 1 | function isArmstrong(n) { 2 | const num = n; 3 | let sum = 0; 4 | while (n > 0) { 5 | sum += Math.pow(n % 10, 3); 6 | n = Math.floor(n / 10); 7 | } 8 | return sum === num; 9 | } 10 | -------------------------------------------------------------------------------- /Loops [Post Class]/SingleDigit.js: -------------------------------------------------------------------------------- 1 | function singleDigit(n) { 2 | let sum = 0; 3 | while (n > 0) { 4 | sum += n % 10; 5 | n = Math.floor(n / 10); 6 | } 7 | if (sum < 10) return sum; 8 | return singleDigit(sum); 9 | } 10 | -------------------------------------------------------------------------------- /Objected Oriented Programming [In Class]/ClassesInJava.java: -------------------------------------------------------------------------------- 1 | static class Student { 2 | // Enter your code here 3 | String name; 4 | int eng; 5 | int maths; 6 | int hindi; 7 | 8 | Student(String name, int eng, int maths, int hindi) { 9 | this.name = name; 10 | this.eng = eng; 11 | this.maths = maths; 12 | this.hindi = hindi; 13 | } 14 | 15 | } 16 | 17 | static Student[] createStudentArray(int n) { 18 | // Enter your code here 19 | Student[] stud = new Student[n]; 20 | for (int i = 0; i < n; i++) { 21 | String name = sc.next(); 22 | int eng = sc.nextInt(); 23 | int maths = sc.nextInt(); 24 | int hindi = sc.nextInt(); 25 | Student s = new Student(name, eng, maths, hindi); 26 | stud[i] = s; 27 | } 28 | return stud; 29 | } 30 | 31 | static int engAverage(Student st[], int n) { 32 | // Enter your code here 33 | int sum = 0; 34 | for (int i = 0; i < n; i++) 35 | sum += st[i].eng; 36 | return sum / n; 37 | } 38 | 39 | static int avgPercentageOfClass(Student st[], int n){ 40 | //Enter your code here 41 | int total = 0; 42 | for(int i = 0; i < n; i++) total += ((st[i].eng + st[i].maths + st[i].hindi) / 3); 43 | return total / n; 44 | } -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Newton School Assignments 2 | Newton School Assignments is the repository which contains the assignments of Newton School November Batch 3. 3 | Here is the list of assignments with their links to the code 4 | 5 | ## Remember 6 | * These codes might not be optimum, the purpose is only to pass the test cases. 7 | * Try to solve these asignments by your own first, then go for these codes. 8 | * You don't need to go to the whole file structure of this repository, scroll down and click the assignment name it will take you to the code. 9 | * The below list is sorted according to the Newton assignments tab. 10 | 11 | ## Status of Assignments and links to the codes 12 | * '✔️' : Means assignment Completed and avaliable 13 | * '❌' : Means assignment not avaliable yet 14 |

15 | 16 | 1. React Router, Using Stateful Lists, Understanding "Keys", Adding Dynamic Styles, ... - Post Class 17 | ___ 18 | 1. ❌ [Golf: Part-2]() 19 | 1. ✔️ [Relatives List React](https://github.com/javid97/Relatives-List-React) 20 | 1. ❌ [React Router easy]() 21 | 1. ❌ [React Router Medium]() 22 |

23 | 1. ✔️ React State & Events, Lifting The State Up, Updating State That Depends On The P ... - In Class 24 | ___ 25 | 1. ✔️ [Holiday List React Plans for holiday?](https://github.com/javid97/React-State-Events-Lifting-The-State-Up-Updating-State-That-Depends-On-The-P-...---In-Class---Ho) 26 |

27 | 1. ✔️ React Handling Side Effects, What are "Side Effects" & Introducing useEffect, Us ... - Post Class 28 | ___ 29 | 1. ✔️ [React Pagination](https://github.com/javid97/React-Handling-Side-Effects-What-are-Side-Effects-Introducing-useEffect-Us-...---Post-Class---) 30 |

31 | 1. ✔️ Stack [Post Class] 32 | ___ 33 | 1. ✔️ [Greater is better](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/GreaterIsBetter.java) 34 | 1. ✔️ [Stack implemetation using linked list](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/Stack%20Implementation%20using%20linked%20list.java) 35 | 1. ✔️ [Nearest Smaller Element](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/Nearest%20Smaller%20Element.java) 36 | 1. ✔️ [Stock Span Problem](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/StockSpanProblem.java) 37 | 1. ✔️ [Stack operations](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/Stack%20Operations.java) 38 | 1. ✔️ [Height Problem](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/Height%20Problem.java) 39 | 1. ✔️ [Infix to Postfix](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/Infix%20to%20Postfix.java) 40 | 1. ✔️ [Array implementation of stack](https://github.com/javid97/Newton-School-Assignments/blob/main/Stack%20%5BPost%20Class%5D/Array%20implementation%20of%20stack.java) 41 |

42 | 43 | 1. ✔️ ArrayList and Linked List [Post Class] 44 | ___ 45 | 1. ✔️ [Delete the Kth node from the end](https://github.com/javid97/Newton-School-Assignments/blob/main/ArrayList%20and%20Linked%20List%20%5BPost%20Class%5D/DeleteTheKthNodeFromTheEnd.java) 46 | 1. ✔️ [Print the Linked List](https://github.com/javid97/Newton-School-Assignments/blob/main/ArrayList%20and%20Linked%20List%20%5BPost%20Class%5D/PrintTheLinkedList.java) 47 | 1. ✔️ [Intersection of two linked list](https://github.com/javid97/Newton-School-Assignments/blob/main/ArrayList%20and%20Linked%20List%20%5BPost%20Class%5D/IntersectionOfTwoLinkedLists.java) 48 | 1. ✔️ [Palindrome List](https://github.com/javid97/Newton-School-Assignments/blob/main/ArrayList%20and%20Linked%20List%20%5BPost%20Class%5D/PalindromeList.java) 49 | 1. ✔️ [Merge two sorted linked list](https://github.com/javid97/Newton-School-Assignments/blob/main/ArrayList%20and%20Linked%20List%20%5BPost%20Class%5D/MergeTwoSortedLinkedLists.java) 50 | 1. ✔️ [Deletion in Doubly Linked List](https://github.com/javid97/Newton-School-Assignments/blob/main/ArrayList%20and%20Linked%20List%20%5BPost%20Class%5D/DeletionInDoublyLinkedList.java) 51 | 1. ✔️ [Reversing a double linked list](https://github.com/javid97/Newton-School-Assignments/blob/main/ArrayList%20and%20Linked%20List%20%5BPost%20Class%5D/ReversingADoublyLinkedList.java) 52 |

53 | 1. ❌ STL [Post Class] 54 | ___ 55 | 1. ❌ Bubble sort in pair array 56 | 1. ❌ Largest subarray of 0's and 1's 57 | 1. ✔️ [Subarray with given sum](https://github.com/javid97/Newton-School-Assignments/blob/main/STL%20%5BPost%20Class%5D/SubArrayWithGivenSum.java) 58 | 1. ❌ Floor and Ceil 59 | 1. ❌ Maximum subarray sum modulo M 60 | 1. ✔️ [Addition of Common Elements](https://github.com/javid97/Newton-School-Assignments/blob/main/STL%20%5BPost%20Class%5D/AdditionOfCommonElements.java) 61 | 1. ❌ Mutating Array 62 | 1. ❌ Pair Sum Existence-Revisited 63 | 1. ✔️ [Max freq](https://github.com/javid97/Newton-School-Assignments/blob/main/STL%20%5BPost%20Class%5D/MaxFreq.java) 64 | 1. ✔️ [Pair Sum in vector](https://github.com/javid97/Newton-School-Assignments/blob/main/STL%20%5BPost%20Class%5D/PairSumVector.java) 65 | 1. ❌ Smaller elements 66 | 1. ✔️ [Remove duplicates from array](https://github.com/javid97/Newton-School-Assignments/blob/main/STL%20%5BPost%20Class%5D/RemoveDuplicatesFromArray.java) 67 |

68 | 69 | 1. ✔️ Strings[Post Class] 70 | ___ 71 | 1. ✔️ [Palindrome](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/Palindrome.js) 72 | 1. ✔️ [Repeating Character - First Appearance Leftmost](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/RepeatingCharacter.js) 73 | 1. ✔️ [String Sum](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/StringSum.js) 74 | 1. ✔️ [Anagram](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/Anagram.js) 75 | 1. ✔️ [Longest Distinct characters in string](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/LongestDistinctCharacters.java) 76 | 1. ✔️ [Reverse](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/Reverse.py) 77 | 1. ✔️ [Is palindrome?](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/isPalindrome.js) 78 | 1. ✔️ [Longest Common Prefix in an Array](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/LongestCommonPrefixInAnArray.js) 79 | 1. ✔️ [Odd characters](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/OddCharacters.js) 80 | 1. ✔️ [Pangram Checking](https://github.com/javid97/Newton-School-Assignments/blob/main/Strings%20%5BPost%20Class%5D/PangramChecking.js) 81 |

82 | 83 | 1. Simple Array Sorting and its implementation [Post Class] 84 | ___ 85 | 1. ✔️ [Sort 0's 1's and 2's](https://github.com/javid97/Newton-School-Assignments/blob/main/Simple%20Array%20Sorting%20and%20its%20implementation%20%5BPost%20Class%5D/Sort0s1s2s.js) 86 | 1. ✔️ [Shopping](https://github.com/javid97/Newton-School-Assignments/blob/main/Simple%20Array%20Sorting%20and%20its%20implementation%20%5BPost%20Class%5D/Shopping.js) 87 | 1. ❌ Maximum Force 88 | 1. ✔️ [Bubble Sort (descending order)](https://github.com/javid97/Newton-School-Assignments/blob/main/Simple%20Array%20Sorting%20and%20its%20implementation%20%5BPost%20Class%5D/bubbleSort(DescendingOrder).js) 89 | 1. ✔️ [Selection Sort](https://github.com/javid97/Newton-School-Assignments/blob/main/Simple%20Array%20Sorting%20and%20its%20implementation%20%5BPost%20Class%5D/SelectionSort.js) 90 | 1. ✔️ [Implementing Insertion sort](https://github.com/javid97/Newton-School-Assignments/blob/main/Simple%20Array%20Sorting%20and%20its%20implementation%20%5BPost%20Class%5D/ImplementingInsertionSort.js) 91 | 1. ✔️ [Implementing Bubble Sort](https://github.com/javid97/Newton-School-Assignments/blob/main/Simple%20Array%20Sorting%20and%20its%20implementation%20%5BPost%20Class%5D/ImplementingBubbleSort.js) 92 | 1. ✔️ [Implementing Merge Sort](https://github.com/javid97/Newton-School-Assignments/blob/main/Simple%20Array%20Sorting%20and%20its%20implementation%20%5BPost%20Class%5D/ImplementingMergeSort.js) 93 |

94 | 95 | 1. ✔️ 2-D Matrix 96 | ___ 97 | 1. ✔️ [Good Cells](https://github.com/javid97/Newton-School-Assignments/blob/main/2-D%20Matrix/GoodCells.js) 98 | 1. ✔️ [A Boolean Matrix Problem](https://github.com/javid97/Newton-School-Assignments/blob/main/2-D%20Matrix/BooleanMatrix.java) 99 | 1. ✔️ [Row with maximum 1's](https://github.com/javid97/Newton-School-Assignments/blob/main/2-D%20Matrix/RowWithMaximum1s.js) 100 |

101 | 102 | 1. ✔️ Functions [Post Class] 103 | ___ 104 | 1. ✔️ [Help Sherlock](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%5BPost%20Class%5D/HelpSherlock.js) 105 |

106 | 107 | 1. ✔️ 1-D Array [Post Class] 108 | ___ 109 | 1. ✔️ [Buildings](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BPost%20Class%5D/Buildings.js) 110 | 1. ✔️ [Is this repeated? (Contest)](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BPost%20Class%5D/IsThisRepeated.java) 111 | 1. ✔️ [Simple Arrangement](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BPost%20Class%5D/SimpleArrangement.js) 112 | 1. ✔️ [Alternate Sum product](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BPost%20Class%5D/AlternateSumproduct.js) 113 | 1. ✔️ [Replace element](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BPost%20Class%5D/ReplaceElement.js) 114 |

115 | 116 | 1. Linear Search and Binary Search [Post Class] 117 | ___ 118 | 1. ✔️ [Square Root Of an Integer](https://github.com/javid97/Newton-School-Assignments/blob/main/Linear%20Search%20and%20Binary%20Search%20%5BPost%20Class%5D/SquareRootOfInteger.js) 119 | 1. ❌ K- sum 120 | 1. ❌ Min Cut Tree 121 | 1. ✔️ [Minimum Element in Sorted and Rotated Array](https://github.com/javid97/Newton-School-Assignments/blob/main/Linear%20Search%20and%20Binary%20Search%20%5BPost%20Class%5D/MinimumElementInSortedArray.java) 122 |

123 | 1. Linear Search and Binary Search [In Class] 124 | ___ 125 | 1. ✔️ [Searching an element in a sorted array](https://github.com/javid97/Newton-School-Assignments/blob/main/Linear%20Search%20and%20Binary%20Search%20%5BIn%20Class%5D/SearchingAnElementInASortedArray.java) 126 | 1. ❌ Kth Smallest Difference 127 | 1. ❌ Shipping Parcels 128 |

129 | 130 | 1. ✔️ Functions & Recursion 131 | ___ 132 | 1. ✔️ [Candy Crush](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion/CandyCrush.java) 133 | 1. ✔️ [Number of ways](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion/NumberOfWays.java) 134 | 1. ✔️ [Fibonacci Numbers](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion/FibonacciNumbers.js) 135 | 1. ✔️ [Sum of digits](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion/SumOfDigits.js) 136 | 1. ✔️ [Sum of Product of Digits of a given number](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion/SumOfProductOfDigitsOfaGivenNumber.js) 137 |

138 | 139 | 1. ✔️ Development Enviornment Setup, Fundamentals of java [In Class] 140 | ___ 141 | 1. ✔️ [Focal length of Spherical Mirror](https://github.com/javid97/Newton-School-Assignments/blob/main/Development%20Enviornment%20Setup%2C%20Fundamentals%20of%20java%20%5BIn%20Class%5D/FocalLengthOfSphericalMirror.java) 142 | 1. ✔️ [Cuboid Perimeter](https://github.com/javid97/Newton-School-Assignments/blob/main/Development%20Enviornment%20Setup%2C%20Fundamentals%20of%20java%20%5BIn%20Class%5D/CuboidPerimeter.java) 143 |

144 | 1. ✔️ Children prop (Concept of Composition), Organizing Component Files, Component fu ... 145 | ___ 146 | 1. ✔️ [Nested List](https://github.com/javid97/Children-prop-Concept-of-Composition-Organizing-Component-Files-Component-fu-...---Post-Class---) 147 |

148 | 1. ✔️ 2-D Matrix [In Class] 149 | ___ 150 | 1. ✔️ [Max sum column](https://github.com/javid97/Newton-School-Assignments/blob/main/2-D%20Matrix%20%5BIn%20Class%5D/MaxSumColumn.js) 151 | 1. ✔️ [Diagonal Sum](https://github.com/javid97/Newton-School-Assignments/blob/main/2-D%20Matrix%20%5BIn%20Class%5D/DiagonalSum.js) 152 |

153 | 1. ✔️ 1-D Array [In Class] 154 | ___ 155 | 1. ✔️ [Sum and Mean](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BIn%20Class%5D/SumAndMean.js "Sum and Mean") 156 | 1. ✔️ [Increasing array](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BIn%20Class%5D/IncreasingArray.java) 157 | 1. ✔️ [Average me](https://github.com/javid97/Newton-School-Assignments/blob/main/1-D%20Array%20%5BIn%20Class%5D/AverageMe.js "Average Me") 158 |

159 | 1. ✔️ Control Structures and Loops [Post Class] 160 | ___ 161 | 1. ✔️ [Newton School Problem](https://github.com/javid97/Newton-School-Assignments/blob/main/Control%20Structures%20and%20Loops%20%5BPost%20Class%5D/NewtonSchoolProblem.java) 162 | 1. ✔️ [Triangle (right angle)](https://github.com/javid97/Newton-School-Assignments/blob/main/Control%20Structures%20and%20Loops%20%5BPost%20Class%5D/TriangleRightAngle.java) 163 | 1. ✔️ [Pattern Printing](https://github.com/javid97/Newton-School-Assignments/blob/main/Control%20Structures%20and%20Loops%20%5BPost%20Class%5D/PatternPrinting.java) 164 |

165 | 1. ✔️ Loops [Post Class] 166 | ___ 167 | 1. ✔️ [Single Digit](https://github.com/javid97/Newton-School-Assignments/blob/main/Loops%20%5BPost%20Class%5D/SingleDigit.js) 168 | 1. ✔️ [Armstrong Number](https://github.com/javid97/Newton-School-Assignments/blob/main/Loops%20%5BPost%20Class%5D/ArmstrongNumber.js) 169 |

170 | 1. ✔️ Objected Oriented Programming [In Class] 171 | ___ 172 | 1. ✔️ [Clases in java](https://github.com/javid97/Newton-School-Assignments/blob/main/Objected%20Oriented%20Programming%20%5BIn%20Class%5D/ClassesInJava.java) 173 |

174 | 175 | 1. ✔️ Functions & Recursion [In Class] 176 | ___ 177 | 1. ✔️ [Power function](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion%20%5BIn%20Class%5D/PowerFunction.js) 178 | 1. ✔️ [Tower of Hanoi](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion%20%5BIn%20Class%5D/TowerOfHanoi.js) 179 | 1. ✔️ [Factorial - Recursion](https://github.com/javid97/Newton-School-Assignments/blob/main/Functions%20%26%20Recursion%20%5BIn%20Class%5D/FactorialRecursion.js) 180 |

181 | 182 | 1. ✔️ (15 Feb 2022) JS Practise Contest 183 | ___ 184 | 1. ✔️ [Todo List - Js](https://github.com/javid97/Newton-School-Assignments/tree/main/JS%20practice%20Contest) 185 | 1. ✔️ [JS Reverse](https://github.com/javid97/Newton-School-Assignments/blob/main/JS%20practice%20Contest/JsReverse.js) 186 |

187 | 188 | 1. ✔️ (8 Feb 2022) JS Contest - 2 189 | ___ 190 | 1. ✔️ [Youtube Likes](https://github.com/javid97/Newton-School-Assignments/blob/main/(8%20Feb%202022)%20Js%20Contest%20-%202/YoutubeLikes.html) 191 | 1. ✔️ [Hot or Cold: Part-1](https://github.com/javid97/Newton-School-Assignments/blob/main/(8%20Feb%202022)%20Js%20Contest%20-%202/HotOrCold.html) 192 | 1. ✔️ [Grocery list](https://github.com/javid97/Newton-School-Assignments/blob/main/(8%20Feb%202022)%20Js%20Contest%20-%202/GroceryList.html) 193 | 1. ✔️ [Javascript Prototypes](https://github.com/javid97/Newton-School-Assignments/blob/main/(8%20Feb%202022)%20Js%20Contest%20-%202/JavascriptPrototypes.js) 194 | 1. ✔️ [Js Error Handling](https://github.com/javid97/Newton-School-Assignments/blob/main/(8%20Feb%202022)%20Js%20Contest%20-%202/JsErrorHandling.js) 195 |

196 | 197 | -------------------------------------------------------------------------------- /STL [Post Class]/AdditionOfCommonElements.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main (String[] args) { 8 | // Your code here 9 | Set set = new HashSet<>(); 10 | Scanner sc = new Scanner(System.in); 11 | int sum = 0; 12 | int N1 = sc.nextInt(); 13 | int N2 = sc.nextInt(); 14 | for(int i = 0; i < N1; i++){ 15 | int n = sc.nextInt(); 16 | set.add(n); 17 | } 18 | for(int i = 0; i < N2; i++){ 19 | int n = sc.nextInt(); 20 | if(set.contains(n)){ 21 | sum += n; 22 | set.remove(n); 23 | } 24 | } 25 | System.out.print(sum); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /STL [Post Class]/MaxFreq.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main (String[] args) { 8 | // Your code here 9 | Scanner sc = new Scanner(System.in); 10 | HashMap map = new HashMap(); 11 | int n = sc.nextInt(); 12 | int[] arr = new int[n]; 13 | for(int i = 0; i < n; i++){ 14 | int a = sc.nextInt(); 15 | if(map.containsKey(a)) map.put(a, map.get(a) + 1); 16 | else map.put(a, 1); 17 | } 18 | int freq = 1; 19 | int maxKey = arr[0]; 20 | for (HashMap.Entry set : map.entrySet()) { 21 | int val = set.getValue(); 22 | int key = set.getKey(); 23 | if(val > freq){ 24 | freq = val; 25 | maxKey = key; 26 | }else if(val == freq){ 27 | if(key > maxKey) maxKey = key; 28 | } 29 | } 30 | System.out.print(maxKey); 31 | } 32 | } -------------------------------------------------------------------------------- /STL [Post Class]/PairSumVector.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main (String[] args) { 8 | // Your code here 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | long sum = 0; 12 | for(int i = 0; i < n; i++){ 13 | int a = sc.nextInt(); 14 | int b = sc.nextInt(); 15 | sum += b; 16 | } 17 | System.out.print(sum); 18 | } 19 | } -------------------------------------------------------------------------------- /STL [Post Class]/RemoveDuplicatesFromArray.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner sc = new Scanner(System.in); 10 | Set set = new HashSet<>(); 11 | int n = sc.nextInt(); 12 | for (int i = 0; i <= n; i++) { 13 | int num = sc.nextInt(); 14 | if (!set.contains(num)) 15 | System.out.print(num + " "); 16 | set.add(num); 17 | } 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /STL [Post Class]/SubArrayWithGivenSum.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main (String[] args) { 8 | // Your code here 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | long k = sc.nextLong(); 12 | int[] arr = new int[n]; 13 | for(int i = 0; i < n; i++) arr[i] = sc.nextInt(); 14 | int i = 0; 15 | int j = 0; 16 | long sum = 0; 17 | boolean found = false; 18 | while(j < n){ 19 | sum += arr[j]; 20 | if(sum == k){ 21 | int start = i + 1; 22 | int end = j + 1; 23 | System.out.print(start + " "+ end); 24 | found = true; 25 | break; 26 | } 27 | else if(sum > k){ 28 | while(sum > k){ 29 | sum -= arr[i]; 30 | i++; 31 | } 32 | if(sum == k){ 33 | int start = i + 1; 34 | int end = j + 1; 35 | System.out.print(start + " "+ end); 36 | found = true; 37 | break; 38 | } 39 | } 40 | j++; 41 | } 42 | if(!found) System.out.print(-1); 43 | } 44 | } -------------------------------------------------------------------------------- /Simple Array Sorting and its implementation [Post Class]/ImplementingBubbleSort.js: -------------------------------------------------------------------------------- 1 | // arr is unsorted array 2 | // n is the number of elements in the array 3 | function bubbleSort(arr, n) { 4 | let swapped = false; 5 | for (let i = 0; i < n; i++) { 6 | for (let j = 0; j < n - i - 1; j++) { 7 | if (arr[j] > arr[j + 1]) { 8 | [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; 9 | swapped = true; 10 | } 11 | } 12 | if (!swapped) break; 13 | } 14 | return arr; 15 | } 16 | -------------------------------------------------------------------------------- /Simple Array Sorting and its implementation [Post Class]/ImplementingInsertionSort.js: -------------------------------------------------------------------------------- 1 | // arr is unsorted array 2 | // n is the number of elements in the array 3 | function insertionSort(arr, n) { 4 | for (let i = 1; i < n; i++) { 5 | let key = arr[i]; 6 | let j = i - 1; 7 | while (j >= 0 && key < arr[j]) { 8 | arr[j + 1] = arr[j]; 9 | j--; 10 | } 11 | arr[j + 1] = key; 12 | } 13 | return arr; 14 | } 15 | -------------------------------------------------------------------------------- /Simple Array Sorting and its implementation [Post Class]/ImplementingMergeSort.js: -------------------------------------------------------------------------------- 1 | // arr is unsorted arr 2 | // n is the number of elements in the arr 3 | function mergeSort(arr, n) { 4 | const half = Math.floor(n / 2); 5 | if (n < 2) return arr; 6 | const left = arr.splice(0, half); 7 | return merge(mergeSort(left, left.length), mergeSort(arr, arr.length)); 8 | } 9 | 10 | function merge(left, right) { 11 | let arr = []; 12 | while (left.length && right.length) { 13 | if (left[0] < right[0]) { 14 | arr.push(left.shift()); 15 | } else { 16 | arr.push(right.shift()); 17 | } 18 | } 19 | return [...arr, ...left, ...right]; 20 | } 21 | -------------------------------------------------------------------------------- /Simple Array Sorting and its implementation [Post Class]/SelectionSort.js: -------------------------------------------------------------------------------- 1 | // arr is unsorted array 2 | // n is the number of elements in the array 3 | function selectionSort(arr, n) { 4 | for (let i = 0; i < n; i++) { 5 | let min = arr[i]; 6 | let idx = i; 7 | for (let j = i; j < n; j++) { 8 | if (arr[j] < min) { 9 | min = arr[j]; 10 | idx = j; 11 | } 12 | } 13 | [arr[i], arr[idx]] = [arr[idx], arr[i]]; 14 | } 15 | return arr; 16 | } 17 | -------------------------------------------------------------------------------- /Simple Array Sorting and its implementation [Post Class]/Shopping.js: -------------------------------------------------------------------------------- 1 | // prices is array containing price of items 2 | // n is the number of elements in the array 3 | // k is the number of elements to buy 4 | function supermarket(prices, n, k) { 5 | prices.sort((a, b) => a - b); 6 | let totalCost = 0; 7 | for (let i = 2; i < k + 2; i++) totalCost += prices[i]; 8 | return totalCost; 9 | } 10 | -------------------------------------------------------------------------------- /Simple Array Sorting and its implementation [Post Class]/Sort0s1s2s.js: -------------------------------------------------------------------------------- 1 | // arr is unsorted array 2 | // n is the number of elements in the array 3 | function zeroOneTwoSort(arr, n) { 4 | let high = n - 1; 5 | let low = 0; 6 | let mid = 0; 7 | while (mid <= high) { 8 | if (arr[mid] === 0) { 9 | [arr[mid], arr[low]] = [arr[low], arr[mid]]; 10 | low++; 11 | mid++; 12 | } else if (arr[mid] === 1) mid++; 13 | else { 14 | [arr[mid], arr[high]] = [arr[high], arr[mid]]; 15 | high--; 16 | } 17 | } 18 | return arr; 19 | } 20 | -------------------------------------------------------------------------------- /Simple Array Sorting and its implementation [Post Class]/bubbleSort(DescendingOrder).js: -------------------------------------------------------------------------------- 1 | function bubbleSort(arr, n) { 2 | let swapped = false; 3 | for (let i = 0; i < n; i++) { 4 | for (let j = 0; j < n - i - 1; j++) { 5 | if (arr[j] < arr[j + 1]) { 6 | [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; 7 | swapped = true; 8 | } 9 | } 10 | if (!swapped) break; 11 | } 12 | return arr; 13 | } 14 | -------------------------------------------------------------------------------- /Stack [Post Class]/Array implementation of stack.java: -------------------------------------------------------------------------------- 1 | /* 2 | int top=-1; // index of current top 3 | int a[] // array which contain element of stack 4 | */ 5 | // function to add element in the stack 6 | //x=element to be added 7 | //size=maximum size of array 8 | void push(int x,int size) 9 | { 10 | //enter your code here 11 | if(top == size - 1) System.out.println("Stack overflow"); 12 | 13 | else{ 14 | if(top == -1) top = 0; 15 | else top++; 16 | a[top] = x; 17 | } 18 | } 19 | 20 | // Function to pop element from stack 21 | void pop() 22 | { 23 | // enter your code here 24 | if(top == -1) System.out.println("Stack underflow"); 25 | 26 | else{ 27 | if(top == 0) top = -1; 28 | else top--; 29 | } 30 | 31 | } 32 | 33 | void top() 34 | { 35 | //enter your code here 36 | if(top == -1) System.out.println("Empty stack"); 37 | else System.out.println(a[top]); 38 | } -------------------------------------------------------------------------------- /Stack [Post Class]/GreaterIsBetter.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main (String[] args) { 8 | // Your code here 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int arr[] = new int[n]; 12 | for(int i = 0; i < n; i++) arr[i] = sc.nextInt(); 13 | 14 | for(int i = 0; i < n; i++){ 15 | int x = i; 16 | int y = i; 17 | int xCount = -1; 18 | int yCount = -1; 19 | while(x >= 0){ 20 | if(arr[x] > arr[i]){ 21 | xCount = x + 1; 22 | break; 23 | } 24 | x--; 25 | } 26 | while(y < n){ 27 | if(arr[y] > arr[i]){ 28 | yCount = y + 1; 29 | break; 30 | } 31 | y++; 32 | } 33 | System.out.print(xCount + yCount + " "); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Stack [Post Class]/Height Problem.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner scan = new Scanner(System.in); 10 | int n = scan.nextInt(); 11 | int[] arr = new int[n]; 12 | for (int i = 0; i < n; i++) { 13 | arr[i] = scan.nextInt(); 14 | boolean found = false; 15 | for (int j = i - 1; j >= 0; j--) { 16 | if (arr[j] < arr[i]) { 17 | System.out.print(arr[j] + " "); 18 | found = true; 19 | break; 20 | } 21 | } 22 | if (!found) 23 | System.out.print(-1 + " "); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Stack [Post Class]/Infix to Postfix.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner scan = new Scanner(System.in); 10 | String infix = scan.nextLine(); 11 | System.out.print(infixToPostfix(infix)); 12 | } 13 | 14 | public static String infixToPostfix(String infix) { 15 | Stack stk = new Stack<>(); 16 | String postfix = ""; 17 | for (int i = 0; i < infix.length(); i++) { 18 | char ch = infix.charAt(i); 19 | 20 | if ((int) ch >= 65 && (int) ch <= 91) 21 | postfix += ch; 22 | 23 | else if (ch == '(') 24 | stk.push(ch); 25 | 26 | else if (ch == ')') { 27 | while (!stk.empty() && stk.peek() != '(') 28 | postfix += stk.pop(); 29 | stk.pop(); 30 | } 31 | 32 | else { 33 | 34 | if (stk.empty()) 35 | stk.push(ch); 36 | 37 | else { 38 | 39 | if (precedence(ch) > precedence(stk.peek())) 40 | stk.push(ch); 41 | 42 | else { 43 | while (!stk.empty() && precedence(ch) <= precedence(stk.peek())) 44 | postfix += stk.pop(); 45 | stk.push(ch); 46 | } 47 | } 48 | } 49 | 50 | } 51 | 52 | while (!stk.empty()) 53 | postfix += stk.pop(); 54 | 55 | return postfix; 56 | } 57 | 58 | public static int precedence(char ch) { 59 | switch (ch) { 60 | case '+': 61 | case '-': 62 | return 1; 63 | case '*': 64 | case '/': 65 | return 2; 66 | case '^': 67 | return 3; 68 | } 69 | return -1; 70 | } 71 | } -------------------------------------------------------------------------------- /Stack [Post Class]/Nearest Smaller Element.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner s = new Scanner(System.in); 10 | int n = s.nextInt(); 11 | int arr[] = new int[n]; 12 | arr[0] = s.nextInt(); 13 | System.out.print(-1 + " "); 14 | for (int i = 1; i < n; i++) { 15 | arr[i] = s.nextInt(); 16 | int j = i - 1; 17 | boolean found = false; 18 | while (j >= 0) { 19 | if (arr[j] <= arr[i]) { 20 | System.out.print(arr[j] + " "); 21 | found = true; 22 | break; 23 | } 24 | j--; 25 | } 26 | if (!found) 27 | System.out.print(-1 + " "); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Stack [Post Class]/Stack Implementation using linked list.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | class Node { 4 | Node next; 5 | int val; 6 | 7 | Node(int val) { 8 | this.val = val; 9 | next = null; 10 | 11 | } 12 | } 13 | */ 14 | 15 | Node top = null; 16 | public void push(int x){ 17 | //enter your code here 18 | Node node = new Node(x); 19 | if(top == null) top = node; 20 | else{ 21 | node.next = top; 22 | top = node; 23 | } 24 | } 25 | 26 | public void pop(){ 27 | //enter your code 28 | if(top != null) top = top.next; 29 | } 30 | 31 | public void top(){ 32 | //enter your code here 33 | if(top == null) System.out.println(0); 34 | else System.out.println(top.val); 35 | } -------------------------------------------------------------------------------- /Stack [Post Class]/Stack Operations.java: -------------------------------------------------------------------------------- 1 | public static void push(Stack st, int x) 2 | { 3 | // your code here 4 | st.push(x); 5 | } 6 | 7 | // Function to pop element from stack 8 | public static void pop(Stack st) 9 | { 10 | //your code here 11 | if(!st.empty()) st.pop(); 12 | } 13 | 14 | public static void top(Stack st) 15 | { 16 | // your code here 17 | if(st.empty()) System.out.println(0); 18 | else System.out.println(st.peek()); 19 | } -------------------------------------------------------------------------------- /Stack [Post Class]/StockSpanProblem.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner s = new Scanner(System.in); 10 | int n = s.nextInt(); 11 | int price[] = new int[n]; 12 | for (int i = 0; i < n; i++) 13 | price[i] = s.nextInt(); 14 | Stack st = new Stack<>(); 15 | st.push(0); 16 | System.out.print(1 + " "); 17 | for (int i = 1; i < n; i++) { 18 | while (!st.empty() && price[st.peek()] <= price[i]) 19 | st.pop(); 20 | int stock = (st.empty()) ? (i + 1) : (i - st.peek()); 21 | System.out.print(stock + " "); 22 | st.push(i); 23 | } 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /Strings [Post Class]/Anagram.js: -------------------------------------------------------------------------------- 1 | // str1 and str2 are the two input strings 2 | function isAnagram(str1, str2) { 3 | if (str1.length !== str2.length) return "NO"; 4 | const s1 = str1.split("").sort().join(""); 5 | const s2 = str2.split("").sort().join(""); 6 | return s1 === s2 ? "YES" : "NO"; 7 | } 8 | -------------------------------------------------------------------------------- /Strings [Post Class]/LongestCommonPrefixInAnArray.js: -------------------------------------------------------------------------------- 1 | // n is number of individual space separated strings inside strings variable, 2 | // strings is the string which contains space separated words. 3 | function longestCommonPrefix(strings, n) { 4 | if (n === 1) return strings; 5 | strings = strings.split(" "); 6 | let commonPrefix = "-1"; 7 | for (let i = 0; i < strings[0].length; i++) { 8 | const char = strings[0][i]; 9 | for (let j = 1; j < n; j++) if (strings[j][i] != char) return commonPrefix; 10 | 11 | commonPrefix === "-1" ? (commonPrefix = char) : (commonPrefix += char); 12 | } 13 | return commonPrefix; 14 | } 15 | -------------------------------------------------------------------------------- /Strings [Post Class]/LongestDistinctCharacters.java: -------------------------------------------------------------------------------- 1 | import java.io.*; // for handling input/output 2 | import java.util.*; // contains Collections framework 3 | 4 | // don't change the name of this class 5 | // you can add inner classes if needed 6 | class Main { 7 | public static void main(String[] args) { 8 | // Your code here 9 | Scanner scan = new Scanner(System.in); 10 | int testcases = scan.nextInt(); 11 | while (testcases > 0) { 12 | String str = scan.next(); 13 | int ans = 0; 14 | int j = 0; 15 | int[] arr = new int[256]; 16 | Arrays.fill(arr, -1); 17 | 18 | for (int i = 0; i < str.length(); i++) { 19 | int index = (int) str.charAt(i); 20 | j = Math.max(j, arr[index] + 1); 21 | ans = Math.max(ans, i - j + 1); 22 | arr[index] = i; 23 | } 24 | System.out.println(ans); 25 | 26 | testcases--; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Strings [Post Class]/OddCharacters.js: -------------------------------------------------------------------------------- 1 | // str is input 2 | function oddChars(str) { 3 | let res = ""; 4 | for (let i = 0; i < str.length; i++) { 5 | if (i % 2 === 0) res += str[i] + " "; 6 | } 7 | return res; 8 | } 9 | -------------------------------------------------------------------------------- /Strings [Post Class]/Palindrome.js: -------------------------------------------------------------------------------- 1 | // s is input 2 | function palindrome(s) { 3 | let countChanges = 0; 4 | if (s.length === 1) return 0; 5 | let low = 0; 6 | let high = s.length - 1; 7 | while (low < high) { 8 | if (s[low] !== s[high]) countChanges++; 9 | low++; 10 | high--; 11 | } 12 | return countChanges; 13 | } 14 | -------------------------------------------------------------------------------- /Strings [Post Class]/PangramChecking.js: -------------------------------------------------------------------------------- 1 | // s is input string, ignore number of testcases for this 2 | function pangrams(s) { 3 | const letters = [ 4 | "a", 5 | "b", 6 | "c", 7 | "d", 8 | "e", 9 | "f", 10 | "g", 11 | "h", 12 | "i", 13 | "j", 14 | "k", 15 | "l", 16 | "m", 17 | "n", 18 | "o", 19 | "p", 20 | "q", 21 | "r", 22 | "s", 23 | "t", 24 | "u", 25 | "v", 26 | "w", 27 | "x", 28 | "y", 29 | "z", 30 | ]; 31 | for (let i = 0; i < 26; i++) { 32 | if (!s.includes(letters[i])) return 0; 33 | } 34 | return 1; 35 | } 36 | -------------------------------------------------------------------------------- /Strings [Post Class]/RepeatingCharacter.js: -------------------------------------------------------------------------------- 1 | // ignore test case number as input 2 | // str is the input string 3 | function leftMostOcurringChar(str) { 4 | str = str.split(""); 5 | for (let i = 0; i < str.length; i++) { 6 | let s = str.slice(i + 1, str.length); 7 | if (s.includes(str[i])) return str[i]; 8 | } 9 | return "-1"; 10 | } 11 | -------------------------------------------------------------------------------- /Strings [Post Class]/Reverse.py: -------------------------------------------------------------------------------- 1 | # Your code here 2 | n=int(input()) 3 | def reverse(n): 4 | return int(str(n)[::-1]) 5 | print(reverse(n)) -------------------------------------------------------------------------------- /Strings [Post Class]/StringSum.js: -------------------------------------------------------------------------------- 1 | function Sum(str) { 2 | return str.split("").reduce((sum, digit) => (sum += Number(digit)), 0); 3 | } 4 | -------------------------------------------------------------------------------- /Strings [Post Class]/isPalindrome.js: -------------------------------------------------------------------------------- 1 | // str is input 2 | function isPalindrome(str) { 3 | let low = 0; 4 | let high = str.length - 1; 5 | while (low <= high) { 6 | if (str[low] !== str[high]) return 0; 7 | low++; 8 | high--; 9 | } 10 | return 1; 11 | } 12 | --------------------------------------------------------------------------------