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 |
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 |
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 |