├── .DS_Store ├── .gitignore ├── All Other Program └── Q3.java ├── All Other Programs ├── FizzBuzz.js ├── IntegerToRoman.js ├── Machine Learning.ipynb ├── Navbar.js ├── PlayerMovementTutorial.cs ├── README.md ├── ReverseLinkedList.js ├── ageCalculator.js ├── binarySearchTree.js ├── calendar.js ├── compareIntegers.js ├── date.html ├── fibonacciSequence.js ├── find-the-duplicate-number ├── greatestCommonDivisor.js ├── index.js ├── numberEncoder.js ├── primeNumbers.js ├── queueImplementation.js ├── shell_Script_tochangeformat.sh ├── signOfProducts.js ├── stackImplementation.js └── tipCalculator.js ├── C Programs ├── Bubble Sorting an Array using pointers.c ├── CaesarCipher.c ├── Calculate Compound Interest.c ├── Complex No Passing Structure to Function with pointer.c ├── Convert Binary Number to Decimal.c ├── Dequeque.c ├── DistanceToCheckpoint.cs ├── Fibonacci.c ├── Make a Rectangle.c ├── NVL_TREE_CHECK.c ├── README.md ├── Shortest_Distance_of_Network.c ├── Spiral Matrix.c ├── SumTwo.c ├── Swap.c ├── armstrong.c ├── c.c ├── do.c ├── factorial.c ├── lab_sheet.c ├── lab_sheet_1.c ├── lab_sheet_2.c ├── lab_sheet_3.c ├── new.c ├── populatearray.c ├── rollerCoaster.c ├── strings.c ├── unionofarray.c └── xox game.c ├── C# Programs ├── Client │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── Client.csproj │ └── Program.cs └── Server │ ├── .vscode │ ├── launch.json │ └── tasks.json │ ├── Program.cs │ └── Server.csproj ├── C++ Programs ├── 1281-subtract-the-product-and-sum-of-digits-of-an-integer │ ├── 1281-subtract-the-product-and-sum-of-digits-of-an-integer.cpp │ ├── NOTES.md │ └── README.md ├── 135-candy │ ├── README.md │ └── candy.cpp ├── 1480-running-sum-of-1d-array │ ├── 1480-running-sum-of-1d-array.cpp │ ├── NOTES.md │ └── README.md ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary │ ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary.cpp │ ├── NOTES.md │ └── README.md ├── 1523-count-odd-numbers-in-an-interval-range │ ├── 1523-count-odd-numbers-in-an-interval-range.cpp │ ├── NOTES.md │ └── README.md ├── 1752-check-if-array-is-sorted-and-rotated │ ├── 1752-check-if-array-is-sorted-and-rotated.cpp │ ├── NOTES.md │ └── README.md ├── 1757-recyclable-and-low-fat-products │ ├── 1757-recyclable-and-low-fat-products.sql │ ├── NOTES.md │ └── README.md ├── 26-remove-duplicates-from-sorted-array ├── 344-reverse-string │ ├── 344-reverse-string.cpp │ ├── NOTES.md │ └── README.md ├── 509-fibonacci-number │ ├── 509-fibonacci-number.cpp │ ├── NOTES.md │ └── README.md ├── 557-reverse-words-in-a-string-iii │ ├── 557-reverse-words-in-a-string-iii.cpp │ ├── NOTES.md │ └── README.md ├── 567-permutation-in-string │ ├── 567-permutation-in-string.cpp │ ├── NOTES.md │ └── README.md ├── 704-binary-search │ ├── 704-binary-search.cpp │ ├── NOTES.md │ └── README.md ├── 724-find-pivot-index │ ├── 724-find-pivot-index.cpp │ ├── NOTES.md │ └── README.md ├── 852-peak-index-in-a-mountain-array │ ├── 852-peak-index-in-a-mountain-array.cpp │ ├── NOTES.md │ └── README.md ├── BellmanFordAlgorithm.cpp ├── Codeforces Problems │ ├── CommentoryBox.cpp │ ├── Friends meeting.cpp │ └── love triangle.cpp ├── DijkstraAlgorithm.cpp ├── FloydWarshallAlgorithm.cpp ├── Greedy │ ├── 134. Gas Station.cpp │ ├── 135-Candy.cpp │ ├── 1561. Max_Coins_You_Can_Get.cpp │ └── 1642. Furthest_Building_You_Can_Reach.cpp ├── Heap_Sort.cpp ├── KosarajuAlgorithm.cpp ├── LargestContiguousArraySum.cpp ├── PascalTriangle.cpp ├── Quick-sort.cpp ├── README.md ├── String-is-palindrome-or-not ├── TravellingSalseman.cpp ├── ans.cpp ├── binary_search.cpp ├── connected_components_undirected_graph.cpp ├── intersectionofLinkedLists.cpp ├── linear_search.cpp ├── mergeSort.cpp ├── palindrome.cpp ├── reverseLinkedList.cpp ├── runTimePolymorphism.cpp ├── size └── twosum.cpp ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Clojure Programs ├── .DS_Store └── Webshop │ ├── .DS_Store │ ├── Dockerfile │ ├── LICENCSE │ ├── README.md │ ├── docker-compose.yml │ ├── img │ └── demo.png │ ├── metro.iml │ ├── project.clj │ ├── resources │ ├── .DS_Store │ └── public │ │ ├── .DS_Store │ │ ├── css │ │ ├── bootstrap.min.css │ │ ├── bootstrap.min.css.map │ │ ├── cat.css │ │ └── custom.css │ │ └── img │ │ ├── products │ │ ├── bacon.jpg │ │ ├── crinklefries.jpg │ │ ├── fryingfat.jpg │ │ ├── garlic.jpg │ │ ├── icecream.jpg │ │ ├── oliveoil.jpg │ │ ├── shrimps.jpg │ │ ├── steakhousefries.jpg │ │ ├── sweetpotatoefries.jpg │ │ └── tortilla.jpg │ │ └── shopping-cart.svg │ ├── src │ └── metro │ │ ├── components │ │ ├── db │ │ │ ├── articles.clj │ │ │ └── postgres.clj │ │ ├── server │ │ │ ├── pedestal.clj │ │ │ └── routes.clj │ │ └── web │ │ │ ├── api.clj │ │ │ ├── blocks.clj │ │ │ ├── health.clj │ │ │ └── views.clj │ │ └── system.clj │ ├── target │ ├── .DS_Store │ ├── default+repl │ │ ├── .DS_Store │ │ ├── classes │ │ │ └── META-INF │ │ │ │ └── maven │ │ │ │ └── metro │ │ │ │ └── metro │ │ │ │ └── pom.properties │ │ ├── repl-port │ │ └── stale │ │ │ └── leiningen.core.classpath.extract-native-dependencies │ ├── default+test+test │ │ ├── .DS_Store │ │ ├── classes │ │ │ └── META-INF │ │ │ │ └── maven │ │ │ │ └── metro │ │ │ │ └── metro │ │ │ │ └── pom.properties │ │ └── stale │ │ │ └── leiningen.core.classpath.extract-native-dependencies │ └── default │ │ ├── .DS_Store │ │ ├── classes │ │ └── META-INF │ │ │ └── maven │ │ │ └── metro │ │ │ └── metro │ │ │ └── pom.properties │ │ └── stale │ │ └── leiningen.core.classpath.extract-native-dependencies │ ├── test │ ├── .DS_Store │ └── metro │ │ ├── .DS_Store │ │ ├── db │ │ └── articles_test.clj │ │ ├── system_test.clj │ │ └── web │ │ └── routes_test.clj │ └── testing.sqlite3 ├── Java Programs ├── CheckForElement.java ├── CheckSortedArray.java ├── Combinations.java ├── CountDigits.java ├── CountFreq.java ├── Factorial.java ├── Factors ├── FirstOccur.java ├── GetIndices.java ├── HeapSort.java ├── KadaneAlgo.java ├── LastOccur.java ├── LeftRotate.java ├── MinMaxInTheArray.java ├── MultiplyMatrices ├── NumberGuessingGame.java ├── Plaindrome.java ├── PowerCalculate.java ├── PowerSet.java ├── PrintNnumber.java ├── README.md ├── RainWaterTrapping.java ├── ReverseRecursion ├── SecondLargest.java ├── SecondLargestElement.java ├── SlidingWindow.java ├── SortStrings ├── SumOfArray.java ├── SumOfNaturalNumbers.java ├── TowerOfHanoi.java ├── TwoPointerAlgo.java ├── WriteFileTemplate.java ├── cShakerSort.java ├── check.java ├── checkDuplicate.java ├── intsum.java ├── jdbc.java ├── jdbcconn.java ├── min.java ├── odd.java ├── rec.java ├── small_large.java ├── sumnavg.java ├── validSquare └── value2.java ├── Java Script Programs ├── BMIcalculator.js ├── Readme.md └── simple-calculation.js ├── LICENSE ├── Python Programs ├── Armstrong.py ├── Automated_Text_on_Image_Using_PIL.py ├── Bubblesort.py ├── Counting_Objects_in_image.py ├── Drawing-Car-Using-Python.py ├── Electricitybill.py ├── Fahrenheit_to_Celsius.py ├── Generate-QR-Code.py ├── Image-to-sketch.py ├── IndianFlag.py ├── LongestPalindromicSubstring.py ├── Minimum Elements to Add to Form a Given Sum.py ├── README.md ├── Unimodal.py ├── binary_search.py ├── binary_tree_inorder_traversal. py ├── binary_tree_preorder_traversal. py ├── binarysearch.py ├── bins_kclosestelements.py ├── calc.py ├── calendar.py ├── count-negatives-in-matrix.py ├── db_access.py ├── electric.py ├── first.py ├── fourth.py ├── image processing with opencv.ipynb ├── longestValidParentheses.py ├── main.py ├── multilevelInheritance.py ├── number_guessing_game.py ├── palindrome.py ├── portscanner.py ├── powerOf2.py ├── printSubArrays.py ├── quiz_game.py ├── second.py ├── send_email.py ├── stone_paper_scissors_game.py ├── stuckYourPC.py ├── third.py └── update_tuple.py ├── README.md ├── Sprig Programs ├── Maze Runner.js ├── Paint_IT.js ├── README.md ├── Shooter JS Game.js ├── Trash IT!.js ├── Trash_IT.js ├── Virtual_Machine.js └── love_lock.js ├── area ├── climbing stairs.cpp └── temp.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /All Other Program/Q3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | class Q3 5 | { 6 | public static void main(String args[]) 7 | { 8 | int a,b,c; 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the First Number : "); 11 | a = sc.nextInt(); 12 | System.out.println("Enter the Second Number : "); 13 | b = sc.nextInt(); 14 | System.out.println("Enter the Third Number : "); 15 | c = sc.nextInt(); 16 | if(a>b && a>c) 17 | { 18 | System.out.println(a+" is the Biggest Number"); 19 | } 20 | else if(b>a && b>c) 21 | { 22 | System.out.println(b+" is the Biggest Number"); 23 | } 24 | else 25 | { 26 | System.out.println(c+" is the Biggest Number"); 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /All Other Programs/FizzBuzz.js: -------------------------------------------------------------------------------- 1 | function fizzy(n) { 2 | let answer = []; 3 | for (let i = 1; i <= n; i++) { 4 | if (i % 5 == 0 && i % 3 == 0) { 5 | answer.push("FizzBuzz"); 6 | } else if (i % 5 == 0) { 7 | answer.push("Buzz"); 8 | } else if (i % 3 == 0) { 9 | answer.push("Fizz"); 10 | } else { 11 | answer.push(i.toString()); 12 | } 13 | } 14 | return answer; 15 | } 16 | console.log(fizzy(15)); 17 | -------------------------------------------------------------------------------- /All Other Programs/IntegerToRoman.js: -------------------------------------------------------------------------------- 1 | function intToRoman(num) { 2 | let result = ""; 3 | while (num) { 4 | if (num >= 1000) { 5 | result += "M"; 6 | num -= 1000; 7 | } else if (num >= 500) { 8 | if (num >= 900) { 9 | result += "CM"; 10 | num -= 900; 11 | } else { 12 | result += "D"; 13 | num -= 500; 14 | } 15 | } else if (num >= 100) { 16 | if (num >= 400) { 17 | result += "CD"; 18 | num -= 400; 19 | } else { 20 | result += "C"; 21 | num -= 100; 22 | } 23 | } else if (num >= 50) { 24 | if (num >= 90) { 25 | result += "XC"; 26 | num -= 90; 27 | } else { 28 | result += "L"; 29 | num -= 50; 30 | } 31 | } else if (num >= 10) { 32 | if (num >= 40) { 33 | result += "XL"; 34 | num -= 40; 35 | } else { 36 | result += "X"; 37 | num -= 10; 38 | } 39 | } else if (num >= 5) { 40 | if (num >= 9) { 41 | result += "IX"; 42 | num -= 9; 43 | } else { 44 | result += "V"; 45 | num -= 5; 46 | } 47 | } else { 48 | if (num >= 4) { 49 | result += "IV"; 50 | num -= 4; 51 | } else { 52 | result += "I"; 53 | num -= 1; 54 | } 55 | } 56 | } 57 | return result; 58 | } 59 | 60 | console.log(intToRoman(5)); 61 | console.log(intToRoman(50)); 62 | console.log(intToRoman(1235)); 63 | console.log(intToRoman(543)); 64 | -------------------------------------------------------------------------------- /All Other Programs/Navbar.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './Navbar.css'; 3 | import {Link} from 'react-router-dom'; 4 | 5 | export default function Navbar(){ 6 | return ( 7 |
8 |
9 |

Arvi CZ Collections sai

10 | Home 🤷‍♂️ 11 |
12 | Wishlist 13 | Account 14 | My Cart 15 |
16 | BestSelled 17 | 42 |
43 | 44 |
45 |
46 |
47 | ) 48 | } -------------------------------------------------------------------------------- /All Other Programs/README.md: -------------------------------------------------------------------------------- 1 | # Upload any interesting Programs in the languages not mentioned above here. 2 | ### Please avoid Spam and Invalid submissions 3 | -------------------------------------------------------------------------------- /All Other Programs/ReverseLinkedList.js: -------------------------------------------------------------------------------- 1 | class ListNode { 2 | constructor(val, next = null) { 3 | this.val = val; 4 | this.next = next; 5 | } 6 | } 7 | 8 | const linkedList = [5, 4, 3, 2, 1].reduce( 9 | (acc, val) => new ListNode(val, acc), 10 | null 11 | ); 12 | 13 | const printList = (head) => { 14 | if (!head) { 15 | return; 16 | } 17 | 18 | console.log(head.val); 19 | printList(head.next); 20 | }; 21 | 22 | 23 | 24 | 25 | var reverseList = function (head) { 26 | let prev = null; 27 | let current = head; 28 | 29 | while (current) { 30 | let nextTemp = current.next; 31 | current.next = prev; 32 | prev = current; 33 | current = nextTemp; 34 | } 35 | 36 | return prev; 37 | }; 38 | 39 | printList(linkedList); 40 | console.log("after reverse"); 41 | printList(reverseList(linkedList)); 42 | -------------------------------------------------------------------------------- /All Other Programs/ageCalculator.js: -------------------------------------------------------------------------------- 1 | const calculateAge = (birthDay, birthMonth, birthYear) => { 2 | let date = new Date(); 3 | let currentDay = date.getDate(); 4 | let currentMonth = 1 + date.getMonth(); 5 | let currentYear = date.getFullYear(); 6 | let monthsLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 7 | 8 | if (birthDay > currentDay) { 9 | currentDay = currentDay + monthsLength[currentMonth - 1] 10 | currentMonth -= 1; 11 | } 12 | 13 | if (birthMonth > currentMonth) { 14 | currentMonth += 12; 15 | currentYear -= 1; 16 | } 17 | 18 | let day = currentDay - birthDay; 19 | let month = currentMonth - birthMonth; 20 | let year = currentYear - birthYear; 21 | 22 | return `Your Age is ${year} Years, ${month} Months and ${day} Days`; 23 | } -------------------------------------------------------------------------------- /All Other Programs/binarySearchTree.js: -------------------------------------------------------------------------------- 1 | class Node{ 2 | 3 | constructor(data) { 4 | 5 | this.data = data; 6 | 7 | this.left = null; 8 | 9 | this.right = null; 10 | 11 | }; 12 | 13 | }; 14 | 15 | class BinarySearchTree{ 16 | 17 | constructor(){ 18 | 19 | this.root = null; 20 | 21 | } 22 | 23 | insert(data){ 24 | 25 | var newNode = new Node(data); 26 | 27 | if(this.root === null){ 28 | 29 | this.root = newNode; 30 | 31 | }else{ 32 | 33 | this.insertNode(this.root, newNode); 34 | 35 | }; 36 | 37 | }; 38 | 39 | insertNode(node, newNode){ 40 | 41 | if(newNode.data < node.data){ 42 | 43 | if(node.left === null){ 44 | 45 | node.left = newNode; 46 | 47 | }else{ 48 | 49 | this.insertNode(node.left, newNode); 50 | 51 | }; 52 | 53 | } else { 54 | 55 | if(node.right === null){ 56 | 57 | node.right = newNode; 58 | 59 | }else{ 60 | 61 | this.insertNode(node.right,newNode); 62 | 63 | }; 64 | 65 | }; 66 | 67 | }; 68 | 69 | }; 70 | 71 | const BST = new BinarySearchTree(); 72 | 73 | BST.insert(1); 74 | 75 | BST.insert(3); 76 | 77 | BST.insert(2); 78 | -------------------------------------------------------------------------------- /All Other Programs/compareIntegers.js: -------------------------------------------------------------------------------- 1 | let compareNumbers = (numberOne, numberTwo) => { 2 | if (numberOne < numberTwo) { 3 | return `${numberTwo} is bigger than ${numberOne}`; 4 | } else if (numberOne === numberTwo) { 5 | return `Both numbers are equal`; 6 | } else { 7 | return `${numberOne} is bigger than ${numberTwo} `; 8 | } 9 | }; 10 | 11 | console.log(compareNumbers(1, 2)); 12 | console.log(compareNumbers(12, 2)); 13 | console.log(compareNumbers(6, 24)); 14 | console.log(compareNumbers(3, 2)); 15 | -------------------------------------------------------------------------------- /All Other Programs/date.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

JavaScript new Date and time

5 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /All Other Programs/fibonacciSequence.js: -------------------------------------------------------------------------------- 1 | const fibonacci = (fibonacciLength) => { 2 | if(checkIfNumbers(fibonacciLength)){ 3 | let result = []; 4 | 5 | for (let index = 0; index < fibonacciLength; index++){ 6 | if (index == 0 || index == 1) {result.push(index);}else{ 7 | result.push(result[index - 1] + result[index - 2]) 8 | } 9 | } 10 | return result.reduce((previousNums, currentNum) => previousNums += " " + currentNum , `Fibonacci Sequence of ${fibonacciLength} is:`); 11 | }else{ 12 | return "ERROR. Value must be a number" 13 | } 14 | } 15 | 16 | const checkIfNumbers = (num1) => !isNaN(num1); -------------------------------------------------------------------------------- /All Other Programs/find-the-duplicate-number: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | 4 | int findDuplicate(vector& nums) { 5 | 6 | 7 | // Tortoise and hare approach 8 | int slow = nums[0]; 9 | int fast = nums[0]; 10 | 11 | do 12 | { 13 | slow = nums[slow]; 14 | fast = nums[nums[fast]]; 15 | }while(slow != fast); 16 | 17 | fast = nums[0]; 18 | while(slow != fast) 19 | { 20 | slow = nums[slow]; 21 | fast = nums[fast]; 22 | } 23 | 24 | return slow; 25 | 26 | 27 | // CANNOT SORT AS IT WILL MODIFY THE ARRAY 28 | // sort(nums.begin(),nums.end()); 29 | 30 | // int k = 0; 31 | 32 | // for(int i =1; i { 2 | while (num1 != num2) { 3 | if (num1 > num2) { 4 | num1 = num1 - num2; 5 | } else { 6 | num2 = num2 - num1; 7 | } 8 | } 9 | 10 | console.log(`Greatest common divider is ${num1}`); 11 | }; 12 | 13 | greatestCommonDivisor(2, 4); 14 | greatestCommonDivisor(20, 40); 15 | greatestCommonDivisor(25, 41); 16 | greatestCommonDivisor(104, 33); 17 | -------------------------------------------------------------------------------- /All Other Programs/numberEncoder.js: -------------------------------------------------------------------------------- 1 | const encoder = (textToEncode, encoderKey) => { 2 | let index = 1; 3 | 4 | return [...textToEncode].reduce((alreadyEncode, charToEncode) => { 5 | alreadyEncode += String.fromCharCode(charToEncode.charCodeAt() + parseInt(String(encoderKey)[index-1])); 6 | index % String(encoderKey).length == 0 ? index = 1 : index++; 7 | return alreadyEncode; 8 | },"") 9 | 10 | } 11 | -------------------------------------------------------------------------------- /All Other Programs/primeNumbers.js: -------------------------------------------------------------------------------- 1 | const primeNumbers = (firstNumber, secondNumber) =>{ 2 | if(checkIfNumbers(firstNumber, secondNumber)){ 3 | let result = ""; 4 | 5 | for (let index = firstNumber; index <= secondNumber; index++){ 6 | if (esPrimo(index) == 1) result += index + " "; 7 | } 8 | 9 | return result; 10 | }else{ 11 | return "ERROR. Both values must be numbers" 12 | } 13 | } 14 | 15 | const checkIfNumbers = (num1, num2) => !isNaN(num1) && !isNaN(num2) 16 | 17 | function esPrimo(num){ 18 | let numsResultCero = 0; 19 | 20 | for (let index = num; index > 1 ; index--){ 21 | if (num % index == 0) numsResultCero++; 22 | } 23 | 24 | return numsResultCero; 25 | } -------------------------------------------------------------------------------- /All Other Programs/queueImplementation.js: -------------------------------------------------------------------------------- 1 | // program to implement queue data structure 2 | 3 | class Queue { 4 | 5 | constructor() { 6 | 7 | this.items = []; 8 | 9 | } 10 | 11 | 12 | 13 | // add element to the queue 14 | 15 | enqueue(element) { 16 | 17 | return this.items.push(element); 18 | 19 | } 20 | 21 | 22 | 23 | // remove element from the queue 24 | 25 | dequeue() { 26 | 27 | if(this.items.length > 0) { 28 | 29 | return this.items.shift(); 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | 37 | // view the last element 38 | 39 | peek() { 40 | 41 | return this.items[this.items.length - 1]; 42 | 43 | } 44 | 45 | 46 | 47 | // check if the queue is empty 48 | 49 | isEmpty(){ 50 | 51 | return this.items.length == 0; 52 | 53 | } 54 | 55 | 56 | 57 | // the size of the queue 58 | 59 | size(){ 60 | 61 | return this.items.length; 62 | 63 | } 64 | 65 | 66 | 67 | // empty the queue 68 | 69 | clear(){ 70 | 71 | this.items = []; 72 | 73 | } 74 | 75 | } 76 | 77 | let queue = new Queue(); 78 | 79 | queue.enqueue(1); 80 | 81 | queue.enqueue(2); 82 | 83 | queue.enqueue(4); 84 | 85 | queue.enqueue(8); 86 | 87 | console.log(queue.items); 88 | 89 | queue.dequeue(); 90 | 91 | console.log(queue.items); 92 | 93 | console.log(queue.peek()); 94 | 95 | console.log(queue.isEmpty()); 96 | 97 | console.log(queue.size()); 98 | 99 | queue.clear(); 100 | 101 | console.log(queue.items); 102 | -------------------------------------------------------------------------------- /All Other Programs/shell_Script_tochangeformat.sh: -------------------------------------------------------------------------------- 1 | echo "Enter Directory:" 2 | read Directory 3 | cd $Directory 4 | echo "Before" 5 | ls 6 | for a in *; 7 | do mv "$a" "$a.new"; 8 | done 9 | echo "After" 10 | ls 11 | -------------------------------------------------------------------------------- /All Other Programs/signOfProducts.js: -------------------------------------------------------------------------------- 1 | let sign = (a, b, c) => { 2 | if (a < 0 && b < 0 && c < 0) { 3 | return `the sign is -`; 4 | } else if (a < 0 && b < 0 && c > 0) { 5 | return `the sign is +`; 6 | } else if (a < 0 && b > 0 && c > 0) { 7 | return `the sign is -`; 8 | } else if (a < 0 && b > 0 && c < 0) { 9 | return `the sign is +`; 10 | } else if (a > 0 && b > 0 && c < 0) { 11 | return `the sign is -`; 12 | } else { 13 | return `the sign is +`; 14 | } 15 | }; 16 | console.log(sign(1, 2, 3)); 17 | console.log(sign(-1, 2, 3)); 18 | console.log(sign(-1, -2, 3)); 19 | console.log(sign(-1, -2, -3)); 20 | console.log(sign(1, -2, 3)); 21 | console.log(sign(1, -2, -3)); 22 | console.log(sign(1, 2, -3)); 23 | -------------------------------------------------------------------------------- /All Other Programs/stackImplementation.js: -------------------------------------------------------------------------------- 1 | // program to implement stack data structure 2 | 3 | class Stack { 4 | 5 | constructor() { 6 | 7 | this.items = []; 8 | 9 | } 10 | 11 | 12 | 13 | // add element to the stack 14 | 15 | add(element) { 16 | 17 | return this.items.push(element); 18 | 19 | } 20 | 21 | 22 | 23 | // remove element from the stack 24 | 25 | remove() { 26 | 27 | if(this.items.length > 0) { 28 | 29 | return this.items.pop(); 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | 37 | // view the last element 38 | 39 | peek() { 40 | 41 | return this.items[this.items.length - 1]; 42 | 43 | } 44 | 45 | 46 | 47 | // check if the stack is empty 48 | 49 | isEmpty(){ 50 | 51 | return this.items.length == 0; 52 | 53 | } 54 | 55 | 56 | 57 | // the size of the stack 58 | 59 | size(){ 60 | 61 | return this.items.length; 62 | 63 | } 64 | 65 | 66 | 67 | // empty the stack 68 | 69 | clear(){ 70 | 71 | this.items = []; 72 | 73 | } 74 | 75 | } 76 | 77 | let stack = new Stack(); 78 | 79 | stack.add(1); 80 | 81 | stack.add(2); 82 | 83 | stack.add(4); 84 | 85 | stack.add(8); 86 | 87 | console.log(stack.items); 88 | 89 | stack.remove(); 90 | 91 | console.log(stack.items); 92 | 93 | console.log(stack.peek()); 94 | 95 | console.log(stack.isEmpty()); 96 | 97 | console.log(stack.size()); 98 | 99 | stack.clear(); 100 | 101 | console.log(stack.items); 102 | -------------------------------------------------------------------------------- /All Other Programs/tipCalculator.js: -------------------------------------------------------------------------------- 1 | const calculateTip = (bill, numOfPerson, tipPercentage) => { 2 | let tip = bill * (tipPercentage / 100); 3 | let totalBill = bill + tip; 4 | let perPersonPay = (totalBill / numOfPerson); 5 | 6 | return ` 7 | Initial Bill: ${bill.toFixed(2)} 8 | Tip Percentage: ${tipPercentage}% 9 | Tip Amount: ${tip.toFixed(2)} 10 | Total: ${totalBill.toFixed(2)} 11 | Each Person Pay: ${perPersonPay.toFixed(2)} 12 | ` 13 | } -------------------------------------------------------------------------------- /C Programs/Bubble Sorting an Array using pointers.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main(){ 3 | int *a,i,j,t,n; 4 | printf("Size of Array : "); 5 | scanf("%d",&n); 6 | printf("Give Array Elements: "); 7 | for(i=0;i *(a+j)){ 13 | t = *(a+i);*(a+i) = *(a+j); 14 | *(a+j) = t; 15 | } 16 | } 17 | } 18 | printf("Sorted array is: "); 19 | for(i=0;i 2 | #include 3 | #include 4 | int main() 5 | { 6 | char buffer[101]; 7 | char* plain; 8 | char* cipher; 9 | int len,i,key; 10 | 11 | printf("Enter Plaintext:"); 12 | gets(buffer); 13 | 14 | printf("Enter Key:"); 15 | scanf("%d",&key); 16 | 17 | len=strlen(buffer); 18 | 19 | plain = (char *) malloc(len + 1); 20 | cipher = (char *) malloc(len + 1); 21 | strcpy(plain, buffer); 22 | 23 | for(i=0;i'z') || (plain[i]<='Z' && cipher[i]>'Z')) 27 | { 28 | cipher[i]=cipher[i]-26; 29 | } 30 | // cipher[i] = ((plain[i]-97)+key)%26+97; 31 | } 32 | printf("Encrypted Text: \n"); 33 | puts(cipher); 34 | 35 | printf("Decrypted Text: \n"); 36 | for(i=0;i='a') 40 | plain[i]=plain[i]+26; 41 | } 42 | puts(plain); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C Programs/Calculate Compound Interest.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | float principal, rate, year, ci; 4 | printf("Enter principal: "); 5 | scanf("%f", &principal); 6 | printf("Enter rate: "); 7 | scanf("%f", &rate); 8 | printf("Enter time in years: "); 9 | scanf("%f", &year); 10 | ci = principal * ((pow((1 + rate / 100), year) - 1)); 11 | printf("Compound interest is: %f\n", ci); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /C Programs/Complex No Passing Structure to Function with pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | typedef struct complex { 3 | float real; 4 | float imag; 5 | } complex; 6 | void add(complex *n1, complex *n2,complex *result) { 7 | result->real = n1->real + n2->real; 8 | result->imag = n1->imag + n2->imag; 9 | } 10 | int main() { 11 | complex n1, n2, result; 12 | printf("For 1st complex number ==>\n"); 13 | printf("Enter the real and imaginary parts: "); 14 | scanf("%f %f", &n1.real, &n1.imag); 15 | printf("\nFor 2nd complex number ==> \n"); 16 | printf("Enter the real and imaginary parts: "); 17 | scanf("%f %f", &n2.real, &n2.imag); 18 | printf("\n"); 19 | add(&n1,& n2,&result); 20 | printf("Sum = %.1f + %.1fi", result.real, result.imag); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C Programs/Convert Binary Number to Decimal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int convert(long long); 5 | 6 | int main() { 7 | long long n; 8 | printf("Enter a binary number: "); 9 | scanf("%lld", &n); 10 | printf("%lld in binary = %d in decimal", n, convert(n)); 11 | return 0; 12 | } 13 | 14 | int convert(long long n) { 15 | int dec = 0, i = 0, rem; 16 | 17 | while (n!=0) { 18 | rem = n % 10; 19 | n /= 10; 20 | dec += rem * pow(2, i); 21 | ++i; 22 | } 23 | return dec; 24 | } 25 | -------------------------------------------------------------------------------- /C Programs/DistanceToCheckpoint.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | 4 | public class DistanceToCheckpoint : MonoBehaviour { 5 | 6 | // Reference to checkpoint position 7 | [SerializeField] 8 | private Transform checkpoint; 9 | 10 | // Reference to UI text that shows the distance value 11 | [SerializeField] 12 | private Text distanceText; 13 | 14 | // Calculated distance value 15 | private float distance; 16 | 17 | // Update is called once per frame 18 | private void Update () { 19 | 20 | // Calculate distance value by X axis 21 | distance = (checkpoint.transform.position.x - transform.position.x); 22 | 23 | // Display distance value via UI text 24 | // distance.ToString("F1") shows value with 1 digit after period 25 | // so 12.234 will be shown as 12.2 for example 26 | // distance.ToString("F2") will show 12.23 in this case 27 | distanceText.text = "Distance: " + distance.ToString("F1") + " meters"; 28 | 29 | // If Cat reaches checkpoint then distance text shows "Finish!" word 30 | if (distance <= 0) 31 | { 32 | distanceText.text = "Finish!"; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /C Programs/Fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | 4 | int i, n; 5 | int t1 = 0, t2 = 1; 6 | int nextTerm = t1 + t2; 7 | printf("Enter the number of terms: "); 8 | scanf("%d", &n); 9 | printf("Fibonacci Series: %d, %d, ", t1, t2); 10 | for (i = 3; i <= n; ++i) { 11 | printf("%d, ", nextTerm); 12 | t1 = t2; 13 | t2 = nextTerm; 14 | nextTerm = t1 + t2; 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C Programs/Make a Rectangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void print_top_bottom_row(int x, int position_x) 5 | { 6 | if (position_x == 1 || position_x == x) 7 | { 8 | putchar('o'); 9 | } 10 | else 11 | { 12 | putchar('-'); 13 | } 14 | } 15 | 16 | void print_middle_row(int x, int position_x) 17 | { 18 | if (position_x == 1 || position_x == x) 19 | { 20 | putchar('|'); 21 | } 22 | else 23 | { 24 | putchar(' '); 25 | } 26 | } 27 | 28 | /* Print the figure itself, using a different char depending 29 | * on the row position where it is placed. */ 30 | void print_figure(int x, int y, int position_x, int position_y) 31 | { 32 | if (position_y == 1 || position_y == y) 33 | { 34 | print_top_bottom_row(x, position_x); 35 | } 36 | else 37 | { 38 | print_middle_row(x, position_x); 39 | } 40 | } 41 | 42 | /* Print a rectangle using the numbers from the parameters as 43 | * width (x) and height (y). 44 | * 45 | * At the end of the first loop we need to reset the position 46 | * x counter and create new line to place the next row*/ 47 | void create_square(int x, int y) 48 | { 49 | int position_x; 50 | int position_y; 51 | 52 | position_x = 1; 53 | position_y = 1; 54 | if (x > 0 && y > 0) 55 | { 56 | while (position_y <= y) 57 | { 58 | while (position_x <= x) 59 | { 60 | print_figure(x, y, position_x, position_y); 61 | position_x++; 62 | } 63 | position_y++; 64 | position_x = 1; 65 | putchar('\n'); 66 | } 67 | } 68 | } 69 | 70 | /* 71 | * Read the numbers from the user and call the function to 72 | * create the rectangle. 73 | */ 74 | int main(int argc, char **argv) 75 | { 76 | if (argc == 3) 77 | create_square(strtol(argv[1], NULL, 10), strtol(argv[2], NULL, 10)); 78 | else 79 | printf("Wrong args. \nUsage: ./a.out x y\n"); 80 | return (0); 81 | } 82 | -------------------------------------------------------------------------------- /C Programs/NVL_TREE_CHECK.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct NODE { 5 | struct NODE* left; 6 | int value; 7 | struct NODE* right; 8 | }node; 9 | 10 | node* root = NULL; 11 | 12 | node* create(int num) { 13 | node* result = (node*)malloc(sizeof(node)); 14 | result->left = NULL; 15 | result->value = num; 16 | result->right = NULL; 17 | return result; 18 | } 19 | int max(int num1, int num2) 20 | { 21 | return (num1 > num2 ) ? num1 : num2; 22 | } 23 | 24 | node* insert(node* node, int key) 25 | { 26 | // If the tree is empty, return a new node 27 | if (node == NULL) { 28 | node = create(key); 29 | } 30 | // Else recur down the tree 31 | if(key < node->value) 32 | node->left = insert(node->left, key); 33 | else if (key > node->value) 34 | node->right = insert(node->right, key); 35 | 36 | return node; 37 | } 38 | 39 | void inorder(node* root) 40 | { 41 | if (root != NULL) { 42 | inorder(root->left); 43 | printf("%d \n", root->value); 44 | inorder(root->right); 45 | } 46 | } 47 | 48 | int height(node* ptr) { 49 | if (ptr == NULL) { 50 | return -1; 51 | } 52 | else { 53 | return 1 + max(height(ptr->left), height(ptr->right)); 54 | } 55 | } 56 | 57 | void isBalance(node* head) { 58 | if (abs(height(head->left) - height(head->right)) <= 1) { 59 | printf("Tree is balanced"); 60 | } 61 | else { printf("Tree is unbalanced"); } 62 | } 63 | 64 | int main() { 65 | /*root = insert(root,25); 66 | insert(root,12); 67 | insert(root,6); 68 | insert(root,-1); 69 | insert(root,-1); 70 | insert(root, 15); 71 | insert(root,-1); 72 | insert(root,-1); 73 | insert(root, 30); 74 | insert(root, 27); 75 | insert(root,-1); 76 | insert(root,-1); 77 | insert(root,42); 78 | insert(root,-1); 79 | insert(root,-1);*/ // Balanced Tree input 80 | 81 | root = insert(root,1); 82 | insert(root,2); 83 | insert(root,3); 84 | insert(root,4); 85 | insert(root,5); 86 | insert(root, 6); 87 | insert(root,7); 88 | insert(root,8); 89 | insert(root, 9); // Unbalanced Tree output 90 | 91 | 92 | inorder(root); 93 | 94 | isBalance(root); 95 | } 96 | -------------------------------------------------------------------------------- /C Programs/README.md: -------------------------------------------------------------------------------- 1 | # Upload any of your interesting C Programs here. 2 | ### Please avoid Spam and Invalid submissions 3 | -------------------------------------------------------------------------------- /C Programs/Spiral Matrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int n,m; 5 | printf("\nNumber of rows : "); 6 | scanf("%d",&m); 7 | printf("\nNumber of columns : "); 8 | scanf("%d",&n); 9 | int arr[m][n]; 10 | int i,j; 11 | printf("\nInput the matrix \n"); 12 | for(i = 0; i < m; i++){ 13 | for(j = 0; j < n; j++){ 14 | scanf("%d",&arr[i][j]); 15 | } 16 | } 17 | printf("\nThe Matrix is \n"); 18 | for(i = 0; i < m; i++){ 19 | for(j = 0; j < n; j++){ 20 | printf("%d ",*(*(arr+i)+j)); 21 | } 22 | printf("\n"); 23 | } 24 | printf("\nSpiral Matrix in linear order is : "); 25 | int k = 0, l = 0; 26 | while(k < m && l < n){ 27 | for(i = l; i < n; i++){ 28 | printf("%d ",*(*(arr+k)+i)); 29 | } 30 | k++; 31 | for(i = k; i < m; i++){ 32 | printf("%d ",*(*(arr+i)+(n-1))); 33 | } 34 | n--; 35 | if(k < m){ 36 | for(i = n-1; i >= 0; --i){ 37 | printf("%d ",*(*(arr+(m-1))+i)); 38 | } 39 | m--; 40 | } 41 | if(l < n){ 42 | for(i=m-1; i >= k; i--){ 43 | printf("%d ",*(*(arr+i)+l)); 44 | } 45 | l++; 46 | } 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /C Programs/SumTwo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int a, b; 9 | float m, n; 10 | scanf("%d %d", &a, &b); 11 | scanf("%f %f", &m, &n); 12 | int sumone = a + b; 13 | int diffone = a - b; 14 | float sumtwo = m + n; 15 | float difftwo = m - n; 16 | printf("%d %d\n", sumone, diffone); 17 | printf("%.1f %.1f", sumtwo, difftwo); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C Programs/Swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int *x,int *y) 4 | { 5 | *x=*x+*y; 6 | *y=*x-*y; 7 | *x=*x-*y; 8 | } 9 | void main() 10 | { 11 | int a=0,b=0; 12 | printf("Enter the two numbers to be swapped:\n"); 13 | scanf("%d",&a); 14 | scanf("%d",&b); 15 | swap(&a,&b); 16 | printf("The numbers after swapped are:\n"); 17 | printf("a=%d\tb=%d",a,b); 18 | } 19 | -------------------------------------------------------------------------------- /C Programs/armstrong.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main(){ 4 | int i,a,b=0,c,d,e,sum=0; 5 | printf("Enter a no."); 6 | scanf("%d",&i); 7 | a=i;e=i; 8 | while(a){ 9 | a=a/10; 10 | b++; 11 | } 12 | while(e){ 13 | c=e%10; 14 | e=e/10; 15 | d=pow(c,b); 16 | sum=sum+d; 17 | } 18 | 19 | 20 | if(sum==i){ 21 | printf("No. is armstrong");} 22 | else{ 23 | printf("No. is not armstong"); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /C Programs/c.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char a[90]; 5 | scanf("%[^\n]",a); 6 | printf("%s",a); 7 | } 8 | -------------------------------------------------------------------------------- /C Programs/do.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int sum,n,a; 5 | printf("enter no."); 6 | scanf("%d",&n); 7 | a=sum(n); 8 | printf("sum=%d",sum)); 9 | 10 | 11 | 12 | } 13 | int sum(n); 14 | { 15 | 16 | 17 | int sum(int n) 18 | { 19 | if(n==1) 20 | return 1; 21 | else 22 | { 23 | return(n+sum(n-1)); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /C Programs/factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n, i; 4 | unsigned long long fact = 1; 5 | printf("Enter an integer: "); 6 | scanf("%d", &n); 7 | 8 | // shows error if the user enters a negative integer 9 | if (n < 0) 10 | printf("Error! Factorial of a negative number doesn't exist."); 11 | else { 12 | for (i = 1; i <= n; ++i) { 13 | fact *= i; 14 | } 15 | printf("Factorial of %d = %llu", n, fact); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C Programs/new.c: -------------------------------------------------------------------------------- 1 | #include \ 2 | char upperName(char*, int);\ 3 | int main()\ 4 | \{\ 5 | char name[20];\ 6 | int i;\ 7 | printf("Enter your name: ");\ 8 | scanf("%s",name);\ 9 | for (i=0;name[i]!='\\0';i++)\ 10 | name[i]=upperName(name,i);\ 11 | printf("\\nYour name in upper case is: %s\\n",name);\ 12 | \}\ 13 | \ 14 | char upperName(char *name, int i)\ 15 | \{\ 16 | if (name[i]>='a' && name[i]<='z')\ 17 | name[i]-=32;\ 18 | return name[i];\ 19 | \}\ 20 | \ 21 | \ 22 | } 23 | -------------------------------------------------------------------------------- /C Programs/populatearray.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | bool chkprime(int n){ 8 | bool prime = true; 9 | 10 | for (int i = 2 ; i < n ; i++){ 11 | if ((n%i) == 0){ 12 | prime = false; 13 | break; 14 | } 15 | } 16 | return prime; 17 | } 18 | 19 | void main(){ 20 | // clock_t start = clock(); 21 | 22 | struct timeval t1,t2,t3,t4; 23 | srand(time(0)); 24 | 25 | int arr[100][100]; 26 | bool prime = true; 27 | 28 | gettimeofday(&t1,NULL); 29 | for(int i = 0 ; i < 100 ; i++){ 30 | for(int j = 0 ; j < 100 ; j++){ 31 | arr[i][j] = rand() % 100 + 1; 32 | } 33 | } 34 | gettimeofday(&t2,NULL); 35 | 36 | gettimeofday(&t3, NULL); 37 | for(int i = 0 ; i < 100 ; i++){ 38 | for(int j = 0 ; j < 100 ; j++){ 39 | prime = chkprime(arr[i][j]); 40 | if (prime == true) { 41 | printf("%d is a prime number\n",arr[i][j]); 42 | } 43 | } 44 | } 45 | gettimeofday(&t4,NULL); 46 | // clock_t end = clock(); 47 | // double time_elapsed_in_seconds = (end - start)/(double)CLOCKS_PER_SEC; 48 | // printf("The time taken is : %f\n", time_elapsed_in_seconds); 49 | 50 | 51 | 52 | double p1,p2; 53 | p1 = t2.tv_usec - t1.tv_usec; 54 | printf("The time taken for populating a 100x100 array is : %10.2fus\n", p1); 55 | 56 | p2 = t4.tv_usec - t3.tv_usec; 57 | printf("The time taken to search for prime numbers in a 100x100 array is : %10.2fus\n", p2); 58 | 59 | 60 | 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /C Programs/strings.c: -------------------------------------------------------------------------------- 1 | //declare char array and read a string from user and count number of characters in string 2 | #include 3 | int main() 4 | { 5 | 6 | char a[20]; 7 | int i=0; 8 | printf("enter name: "); 9 | scanf("%s",a); 10 | while(a[i]!='\0') 11 | {i++; 12 | } 13 | printf("%d",i); 14 | } 15 | -------------------------------------------------------------------------------- /C Programs/unionofarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main(){ 3 | int a[50],b[50],c,d,i,j,f=0,g; 4 | printf("Enter size of array 1:\n"); 5 | printf("Enter size of array 2:\n"); 6 | scanf("%d%d",&c,&d); 7 | for(i=0;i 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /C# Programs/Client/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Text; 5 | 6 | public class SynchronousSocketClient { 7 | 8 | public static void StartClient() { 9 | // Data buffer for incoming data. 10 | byte[] bytes = new byte[1024]; 11 | 12 | // Connect to a remote device. 13 | try { 14 | // Establish the remote endpoint for the socket. 15 | // This example uses port 11000 on the local computer. 16 | IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); 17 | IPAddress ipAddress = ipHostInfo.AddressList[0]; 18 | IPEndPoint remoteEP = new IPEndPoint(ipAddress,11000); 19 | 20 | // Create a TCP/IP socket. 21 | Socket sender = new Socket(ipAddress.AddressFamily, 22 | SocketType.Stream, ProtocolType.Tcp ); 23 | 24 | // Connect the socket to the remote endpoint. Catch any errors. 25 | try { 26 | sender.Connect(remoteEP); 27 | 28 | Console.WriteLine("Socket connected to {0}", 29 | sender.RemoteEndPoint.ToString()); 30 | 31 | // Encode the data string into a byte array. 32 | byte[] msg = Encoding.ASCII.GetBytes("This is a test"); 33 | 34 | // Send the data through the socket. 35 | int bytesSent = sender.Send(msg); 36 | 37 | // Receive the response from the remote device. 38 | int bytesRec = sender.Receive(bytes); 39 | Console.WriteLine("Echoed test = {0}", 40 | Encoding.ASCII.GetString(bytes,0,bytesRec)); 41 | 42 | // Release the socket. 43 | sender.Shutdown(SocketShutdown.Both); 44 | sender.Close(); 45 | 46 | } catch (ArgumentNullException ane) { 47 | Console.WriteLine("ArgumentNullException : {0}",ane.ToString()); 48 | } catch (SocketException se) { 49 | Console.WriteLine("SocketException : {0}",se.ToString()); 50 | } catch (Exception e) { 51 | Console.WriteLine("Unexpected exception : {0}", e.ToString()); 52 | } 53 | 54 | } catch (Exception e) { 55 | Console.WriteLine( e.ToString()); 56 | } 57 | } 58 | 59 | public static int Main(String[] args) { 60 | StartClient(); 61 | return 0; 62 | } 63 | } -------------------------------------------------------------------------------- /C# Programs/Server/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | // Use IntelliSense to find out which attributes exist for C# debugging 6 | // Use hover for the description of the existing attributes 7 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/bin/Debug/net6.0/Server.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}", 16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console 17 | "console": "internalConsole", 18 | "stopAtEntry": false 19 | }, 20 | { 21 | "name": ".NET Core Attach", 22 | "type": "coreclr", 23 | "request": "attach" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /C# Programs/Server/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Server.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/Server.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "--project", 36 | "${workspaceFolder}/Server.csproj" 37 | ], 38 | "problemMatcher": "$msCompile" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /C# Programs/Server/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Text; 5 | 6 | public class SynchronousSocketListener { 7 | 8 | // Incoming data from the client. 9 | public static string data = null; 10 | 11 | public static void StartListening() { 12 | // Data buffer for incoming data. 13 | byte[] bytes = new Byte[1024]; 14 | 15 | // Establish the local endpoint for the socket. 16 | // Dns.GetHostName returns the name of the 17 | // host running the application. 18 | IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); 19 | IPAddress ipAddress = ipHostInfo.AddressList[0]; 20 | IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000); 21 | 22 | // Create a TCP/IP socket. 23 | Socket listener = new Socket(ipAddress.AddressFamily, 24 | SocketType.Stream, ProtocolType.Tcp ); 25 | 26 | // Bind the socket to the local endpoint and 27 | // listen for incoming connections. 28 | try { 29 | listener.Bind(localEndPoint); 30 | listener.Listen(10); 31 | 32 | // Start listening for connections. 33 | while (true) { 34 | Console.WriteLine("Waiting for a connection..."); 35 | // Program is suspended while waiting for an incoming connection. 36 | Socket handler = listener.Accept(); 37 | data = null; 38 | 39 | // An incoming connection needs to be processed. 40 | while (true) { 41 | int bytesRec = handler.Receive(bytes); 42 | data += Encoding.ASCII.GetString(bytes,0,bytesRec); 43 | if (data.IndexOf("") > -1) { 44 | break; 45 | } 46 | } 47 | 48 | // Show the data on the console. 49 | Console.WriteLine( "Text received : {0}", data); 50 | 51 | // Echo the data back to the client. 52 | byte[] msg = Encoding.ASCII.GetBytes(data); 53 | 54 | handler.Send(msg); 55 | handler.Shutdown(SocketShutdown.Both); 56 | handler.Close(); 57 | } 58 | 59 | } catch (Exception e) { 60 | Console.WriteLine(e.ToString()); 61 | } 62 | 63 | Console.WriteLine("\nPress ENTER to continue..."); 64 | Console.Read(); 65 | 66 | } 67 | 68 | public static int Main(String[] args) { 69 | StartListening(); 70 | return 0; 71 | } 72 | } -------------------------------------------------------------------------------- /C# Programs/Server/Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /C++ Programs/1281-subtract-the-product-and-sum-of-digits-of-an-integer/1281-subtract-the-product-and-sum-of-digits-of-an-integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int subtractProductAndSum(int n) { 4 | int product=1; 5 | int sum=0; 6 | while(n!=0){ 7 | int rem = n%10; 8 | product = product * rem; 9 | sum=sum+rem; 10 | n=n/10; 11 | } 12 | int result = product-sum; 13 | return result; 14 | } 15 | }; -------------------------------------------------------------------------------- /C++ Programs/1281-subtract-the-product-and-sum-of-digits-of-an-integer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /C++ Programs/1281-subtract-the-product-and-sum-of-digits-of-an-integer/README.md: -------------------------------------------------------------------------------- 1 |

1281. Subtract the Product and Sum of Digits of an Integer

Easy


Given an integer number n, return the difference between the product of its digits and the sum of its digits. 2 |

 

3 |

Example 1:

4 | 5 |
Input: n = 234
 6 | Output: 15 
 7 | Explanation: 
 8 | Product of digits = 2 * 3 * 4 = 24 
 9 | Sum of digits = 2 + 3 + 4 = 9 
10 | Result = 24 - 9 = 15
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: n = 4421
16 | Output: 21
17 | Explanation: 
18 | Product of digits = 4 * 4 * 2 * 1 = 32 
19 | Sum of digits = 4 + 4 + 2 + 1 = 11 
20 | Result = 32 - 11 = 21
21 | 
22 | 23 |

 

24 |

Constraints:

25 | 26 |
    27 |
  • 1 <= n <= 10^5
  • 28 |
29 |
-------------------------------------------------------------------------------- /C++ Programs/135-candy/README.md: -------------------------------------------------------------------------------- 1 |

135 Candy

HARD


There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. 2 | Children with a higher rating get more candies than their neighbors.. 3 | 4 |

Return the minimum number of candies you need to have to distribute the candies to the children.

5 | 6 |

 

7 |

Example 1:

8 | 9 |
Input: ratings = [1,0,2]
10 | Output: 5
11 | Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively..
12 | 13 | -------------------------------------------------------------------------------- /C++ Programs/135-candy/candy.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/candy/ 2 | 3 | class Solution { 4 | public: 5 | 6 | int candy(vector& ratings) { 7 | int n = ratings.size(); 8 | int candy = n, i=1; 9 | while(i ratings [i-1]){ 18 | peak++; 19 | candy += peak; 20 | i++; 21 | if(i == n) return candy; 22 | } 23 | 24 | //For decreasing slope 25 | int valley = 0; 26 | while(i runningSum(vector& nums) { 4 | vector res(nums.size()); 5 | if(nums.size()==0){ 6 | return res; 7 | } 8 | res[0]=nums[0]; 9 | for(int i=1;i1480. Running Sum of 1d Array

Easy


Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).

2 | 3 |

Return the running sum of nums.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [1,2,3,4]
 9 | Output: [1,3,6,10]
10 | Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
11 | 12 |

Example 2:

13 | 14 |
Input: nums = [1,1,1,1,1]
15 | Output: [1,2,3,4,5]
16 | Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
17 | 18 |

Example 3:

19 | 20 |
Input: nums = [3,1,2,10,1]
21 | Output: [3,4,6,16,17]
22 | 
23 | 24 |

 

25 |

Constraints:

26 | 27 |
    28 |
  • 1 <= nums.length <= 1000
  • 29 |
  • -10^6 <= nums[i] <= 10^6
  • 30 |
-------------------------------------------------------------------------------- /C++ Programs/1491-average-salary-excluding-the-minimum-and-maximum-salary/1491-average-salary-excluding-the-minimum-and-maximum-salary.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double average(vector& salary) { 4 | int max=salary[0]; 5 | int min=salary[0]; 6 | for(int i=1;imax){ 8 | max=salary[i]; 9 | } 10 | if(salary[i]1491. Average Salary Excluding the Minimum and Maximum Salary

Easy


You are given an array of unique integers salary where salary[i] is the salary of the ith employee.

2 | 3 |

Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5 of the actual answer will be accepted.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: salary = [4000,3000,1000,2000]
 9 | Output: 2500.00000
10 | Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively.
11 | Average salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500
12 | 
13 | 14 |

Example 2:

15 | 16 |
Input: salary = [1000,2000,3000]
17 | Output: 2000.00000
18 | Explanation: Minimum salary and maximum salary are 1000 and 3000 respectively.
19 | Average salary excluding minimum and maximum salary is (2000) / 1 = 2000
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • 3 <= salary.length <= 100
  • 27 |
  • 1000 <= salary[i] <= 106
  • 28 |
  • All the integers of salary are unique.
  • 29 |
30 |
-------------------------------------------------------------------------------- /C++ Programs/1523-count-odd-numbers-in-an-interval-range/1523-count-odd-numbers-in-an-interval-range.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countOdds(int low, int high) { 4 | if(low%2==0) 5 | low++; 6 | if(high%2==0) 7 | high--; 8 | int ans=(high-low)/2; 9 | return ans+1; 10 | } 11 | }; -------------------------------------------------------------------------------- /C++ Programs/1523-count-odd-numbers-in-an-interval-range/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /C++ Programs/1523-count-odd-numbers-in-an-interval-range/README.md: -------------------------------------------------------------------------------- 1 |

1523. Count Odd Numbers in an Interval Range

Easy


Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: low = 3, high = 7
 7 | Output: 3
 8 | Explanation: The odd numbers between 3 and 7 are [3,5,7].
9 | 10 |

Example 2:

11 | 12 |
Input: low = 8, high = 10
13 | Output: 1
14 | Explanation: The odd numbers between 8 and 10 are [9].
15 | 16 |

 

17 |

Constraints:

18 | 19 |
    20 |
  • 0 <= low <= high <= 10^9
  • 21 |
-------------------------------------------------------------------------------- /C++ Programs/1752-check-if-array-is-sorted-and-rotated/1752-check-if-array-is-sorted-and-rotated.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool check(vector& nums) { 4 | int count=0; 5 | int n = nums.size(); 6 | for(int i=1;inums[i]){ 8 | count++; 9 | } 10 | } 11 | if(nums[n-1]>nums[0]){ 12 | count++; 13 | } 14 | return count<=1; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /C++ Programs/1752-check-if-array-is-sorted-and-rotated/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /C++ Programs/1752-check-if-array-is-sorted-and-rotated/README.md: -------------------------------------------------------------------------------- 1 |

1752. Check if Array Is Sorted and Rotated

Easy


Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.

2 | 3 |

There may be duplicates in the original array.

4 | 5 |

Note: An array A rotated by x positions results in an array B of the same length such that A[i] == B[(i+x) % A.length], where % is the modulo operation.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
Input: nums = [3,4,5,1,2]
11 | Output: true
12 | Explanation: [1,2,3,4,5] is the original sorted array.
13 | You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].
14 | 
15 | 16 |

Example 2:

17 | 18 |
Input: nums = [2,1,3,4]
19 | Output: false
20 | Explanation: There is no sorted array once rotated that can make nums.
21 | 
22 | 23 |

Example 3:

24 | 25 |
Input: nums = [1,2,3]
26 | Output: true
27 | Explanation: [1,2,3] is the original sorted array.
28 | You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.
29 | 
30 | 31 |

 

32 |

Constraints:

33 | 34 |
    35 |
  • 1 <= nums.length <= 100
  • 36 |
  • 1 <= nums[i] <= 100
  • 37 |
38 |
-------------------------------------------------------------------------------- /C++ Programs/1757-recyclable-and-low-fat-products/1757-recyclable-and-low-fat-products.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | select product_id from products 3 | where low_fats='Y' and recyclable='Y' -------------------------------------------------------------------------------- /C++ Programs/1757-recyclable-and-low-fat-products/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /C++ Programs/1757-recyclable-and-low-fat-products/README.md: -------------------------------------------------------------------------------- 1 |

1757. Recyclable and Low Fat Products

Easy


Table: Products

2 | 3 |
+-------------+---------+
 4 | | Column Name | Type    |
 5 | +-------------+---------+
 6 | | product_id  | int     |
 7 | | low_fats    | enum    |
 8 | | recyclable  | enum    |
 9 | +-------------+---------+
10 | product_id is the primary key for this table.
11 | low_fats is an ENUM of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
12 | recyclable is an ENUM of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
13 | 14 |

 

15 | 16 |

Write an SQL query to find the ids of products that are both low fat and recyclable.

17 | 18 |

Return the result table in any order.

19 | 20 |

The query result format is in the following example.

21 | 22 |

 

23 |

Example 1:

24 | 25 |
Input: 
26 | Products table:
27 | +-------------+----------+------------+
28 | | product_id  | low_fats | recyclable |
29 | +-------------+----------+------------+
30 | | 0           | Y        | N          |
31 | | 1           | Y        | Y          |
32 | | 2           | N        | Y          |
33 | | 3           | Y        | Y          |
34 | | 4           | N        | N          |
35 | +-------------+----------+------------+
36 | Output: 
37 | +-------------+
38 | | product_id  |
39 | +-------------+
40 | | 1           |
41 | | 3           |
42 | +-------------+
43 | Explanation: Only products 1 and 3 are both low fat and recyclable.
44 | 
45 |
-------------------------------------------------------------------------------- /C++ Programs/26-remove-duplicates-from-sorted-array: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | sort (nums.begin(),nums.end()); 5 | int count=0; 6 | for (int i =0;i& s) { 4 | int start=0; 5 | int e=s.size()-1; 6 | while(start344. Reverse String

Easy


Write a function that reverses a string. The input string is given as an array of characters s.

2 | 3 |

You must do this by modifying the input array in-place with O(1) extra memory.

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = ["h","e","l","l","o"]
 8 | Output: ["o","l","l","e","h"]
 9 | 

Example 2:

10 |
Input: s = ["H","a","n","n","a","h"]
11 | Output: ["h","a","n","n","a","H"]
12 | 
13 |

 

14 |

Constraints:

15 | 16 | 20 |
-------------------------------------------------------------------------------- /C++ Programs/509-fibonacci-number/509-fibonacci-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int fib(int n) { 4 | if(n==0){ 5 | return 0; 6 | } 7 | if(n==1){ 8 | return 1; 9 | } 10 | int ans= fib(n-1)+fib(n-2); 11 | return ans; 12 | } 13 | }; -------------------------------------------------------------------------------- /C++ Programs/509-fibonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /C++ Programs/509-fibonacci-number/README.md: -------------------------------------------------------------------------------- 1 |

509. Fibonacci Number

Easy


The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

2 | 3 |
F(0) = 0, F(1) = 1
 4 | F(n) = F(n - 1) + F(n - 2), for n > 1.
 5 | 
6 | 7 |

Given n, calculate F(n).

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: n = 2
13 | Output: 1
14 | Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
15 | 
16 | 17 |

Example 2:

18 | 19 |
Input: n = 3
20 | Output: 2
21 | Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
22 | 
23 | 24 |

Example 3:

25 | 26 |
Input: n = 4
27 | Output: 3
28 | Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
29 | 
30 | 31 |

 

32 |

Constraints:

33 | 34 |
    35 |
  • 0 <= n <= 30
  • 36 |
37 |
-------------------------------------------------------------------------------- /C++ Programs/557-reverse-words-in-a-string-iii/557-reverse-words-in-a-string-iii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string reverseWords(string s) { 4 | int i=0; 5 | for(int i=0; i557. Reverse Words in a String III

Easy


Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

2 | 3 |

 

4 |

Example 1:

5 |
Input: s = "Let's take LeetCode contest"
 6 | Output: "s'teL ekat edoCteeL tsetnoc"
 7 | 

Example 2:

8 |
Input: s = "God Ding"
 9 | Output: "doG gniD"
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= s.length <= 5 * 104
  • 16 |
  • s contains printable ASCII characters.
  • 17 |
  • s does not contain any leading or trailing spaces.
  • 18 |
  • There is at least one word in s.
  • 19 |
  • All the words in s are separated by a single space.
  • 20 |
21 |
-------------------------------------------------------------------------------- /C++ Programs/567-permutation-in-string/567-permutation-in-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | private: 3 | bool checkEqual(int a[26],int b[26]){ 4 | for(int i=0;i<26;i++){ 5 | if(a[i]!=b[i]) 6 | return 0; 7 | } 8 | return 1; 9 | } 10 | public: 11 | bool checkInclusion(string s1, string s2) { 12 | int count1[26]={0}; 13 | for (int i=0;i567. Permutation in String

Medium


Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

2 | 3 |

In other words, return true if one of s1's permutations is the substring of s2.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: s1 = "ab", s2 = "eidbaooo"
 9 | Output: true
10 | Explanation: s2 contains one permutation of s1 ("ba").
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: s1 = "ab", s2 = "eidboaoo"
16 | Output: false
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= s1.length, s2.length <= 104
  • 24 |
  • s1 and s2 consist of lowercase English letters.
  • 25 |
26 |
-------------------------------------------------------------------------------- /C++ Programs/704-binary-search/704-binary-search.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& nums, int target) { 4 | int low=0; 5 | int high=nums.size()-1; 6 | while(low<=high){ 7 | int mid=low+(high-low)/2; 8 | if(nums[mid]==target) 9 | { 10 | return mid; 11 | } 12 | if(nums[mid]704. Binary Search

Easy


Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

2 | 3 |

You must write an algorithm with O(log n) runtime complexity.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [-1,0,3,5,9,12], target = 9
 9 | Output: 4
10 | Explanation: 9 exists in nums and its index is 4
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: nums = [-1,0,3,5,9,12], target = 2
16 | Output: -1
17 | Explanation: 2 does not exist in nums so return -1
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • 1 <= nums.length <= 104
  • 25 |
  • -104 < nums[i], target < 104
  • 26 |
  • All the integers in nums are unique.
  • 27 |
  • nums is sorted in ascending order.
  • 28 |
29 |
-------------------------------------------------------------------------------- /C++ Programs/724-find-pivot-index/724-find-pivot-index.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int pivotIndex(vector& nums) { 4 | int sum=0; 5 | for(int i=0;i724. Find Pivot Index

Easy


Given an array of integers nums, calculate the pivot index of this array.

2 | 3 |

The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.

4 | 5 |

If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.

6 | 7 |

Return the leftmost pivot index. If no such index exists, return -1.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
Input: nums = [1,7,3,6,5,6]
13 | Output: 3
14 | Explanation:
15 | The pivot index is 3.
16 | Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11
17 | Right sum = nums[4] + nums[5] = 5 + 6 = 11
18 | 
19 | 20 |

Example 2:

21 | 22 |
Input: nums = [1,2,3]
23 | Output: -1
24 | Explanation:
25 | There is no index that satisfies the conditions in the problem statement.
26 | 27 |

Example 3:

28 | 29 |
Input: nums = [2,1,-1]
30 | Output: 0
31 | Explanation:
32 | The pivot index is 0.
33 | Left sum = 0 (no elements to the left of index 0)
34 | Right sum = nums[1] + nums[2] = 1 + -1 = 0
35 | 
36 | 37 |

 

38 |

Constraints:

39 | 40 |
    41 |
  • 1 <= nums.length <= 104
  • 42 |
  • -1000 <= nums[i] <= 1000
  • 43 |
44 | 45 |

 

46 |

Note: This question is the same as 1991: https://leetcode.com/problems/find-the-middle-index-in-array/

47 |
-------------------------------------------------------------------------------- /C++ Programs/852-peak-index-in-a-mountain-array/852-peak-index-in-a-mountain-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int peakIndexInMountainArray(vector& arr) { 4 | int s=0; 5 | int e=arr.size()-1; 6 | int mid= s + (e-s)/2; 7 | while(s852. Peak Index in a Mountain Array

Easy


Let's call an array arr a mountain if the following properties hold:

2 | 3 |
    4 |
  • arr.length >= 3
  • 5 |
  • There exists some i with 0 < i < arr.length - 1 such that: 6 |
      7 |
    • arr[0] < arr[1] < ... arr[i-1] < arr[i]
    • 8 |
    • arr[i] > arr[i+1] > ... > arr[arr.length - 1]
    • 9 |
    10 |
  • 11 |
12 | 13 |

Given an integer array arr that is guaranteed to be a mountain, return any i such that arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

14 | 15 |

 

16 |

Example 1:

17 | 18 |
Input: arr = [0,1,0]
19 | Output: 1
20 | 
21 | 22 |

Example 2:

23 | 24 |
Input: arr = [0,2,1,0]
25 | Output: 1
26 | 
27 | 28 |

Example 3:

29 | 30 |
Input: arr = [0,10,5,2]
31 | Output: 1
32 | 
33 | 34 |

 

35 |

Constraints:

36 | 37 |
    38 |
  • 3 <= arr.length <= 104
  • 39 |
  • 0 <= arr[i] <= 106
  • 40 |
  • arr is guaranteed to be a mountain array.
  • 41 |
42 | 43 |

 

44 | Follow up: Finding the O(n) is straightforward, could you find an O(log(n)) solution?
-------------------------------------------------------------------------------- /C++ Programs/BellmanFordAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | //BellmanFordAlgorithm 2 | #include 3 | using namespace std; 4 | struct edge 5 | { 6 | int u; 7 | int v; 8 | int wt; 9 | }; 10 | struct edge e[100001]; 11 | int dist[100001]; 12 | int main() 13 | { 14 | int i, j, n, m, u, v, wt; 15 | cin>>n>>m; 16 | for(i=1;i<=m;i++) 17 | { 18 | cin>>u>>v>>wt; 19 | e[i].u=u; 20 | e[i].v=v; 21 | e[i].wt=wt; 22 | } 23 | for(i=0;i<100001;i++) 24 | dist[i]=100001; 25 | dist[1]=0; 26 | for(i=1;i(dist[e[j].u]+e[j].wt)) 31 | dist[e[j].v]=dist[e[j].u]+e[j].wt; 32 | } 33 | } 34 | for(i=1;i<=n;i++) 35 | cout< "< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int n,m,a,b, cost = 0, x; 6 | cin>>n>>m>>a>>b; 7 | if(n % m) 8 | { 9 | x = n%m; 10 | cost = x*b; 11 | x = m - x; 12 | if(x*a < cost) 13 | cost = x*a; 14 | } 15 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int a, b, result = 0, i = 0, j = 0, n = 1; 7 | cin>>a>>b; 8 | for(;abs(a-b)!=0;) 9 | { 10 | if(n%2) 11 | { 12 | result += ++j; 13 | n++; 14 | if(a>b) 15 | a--; 16 | else 17 | a++; 18 | } 19 | else 20 | { 21 | result += ++i; 22 | n++; 23 | if(a 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i; 6 | bool flag = false; 7 | cin >> n; 8 | int *a = (int *)malloc((sizeof(int)*(n+1))); 9 | int j, t1, t2; 10 | for (i = 1; i <= n; i++) 11 | { 12 | cin >> a[i]; 13 | } 14 | for (i = 1; i <= n; i++) 15 | { 16 | j = a[i]; 17 | t1 = a[j]; 18 | t2 = a[t1]; 19 | if ((a[j] == t1) && (a[t1] == t2) && (a[t2] == j)) 20 | flag = true; 21 | } 22 | if (flag == true) 23 | cout << "YES"; 24 | else 25 | cout << "NO"; 26 | //system("pause"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C++ Programs/DijkstraAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | //DijkstraAlgorithm 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | vector>adj[100001]; 7 | priority_queue, vector>, greater>>pq; 8 | int dist[100001]; 9 | int main() 10 | { 11 | int i, n, m, u, v, wt; 12 | cin>>n>>m; 13 | for(i=1;i<=m;i++) 14 | { 15 | cin>>u>>v>>wt; 16 | adj[u].push_back(make_pair(v, wt)); 17 | adj[v].push_back(make_pair(u, wt)); 18 | } 19 | for(i=0;i<100001;i++) 20 | dist[i]=100001; 21 | dist[1]=0; 22 | pq.push(make_pair(0, 1)); 23 | while(pq.empty()==0) 24 | { 25 | u=pq.top().second; 26 | pq.pop(); 27 | for(auto j:adj[u]) 28 | { 29 | if(dist[j.first]>(dist[u]+j.second)) 30 | { 31 | dist[j.first]=dist[u]+j.second; 32 | pq.push(make_pair(dist[j.first], j.first)); 33 | } 34 | } 35 | } 36 | for(i=1;i<=n;i++) 37 | cout< "< 3 | using namespace std; 4 | int dist[1001][1001]; 5 | int main() 6 | { 7 | int i, j, k, n, m, u, v, wt; 8 | for(i=0;i<1001;i++) 9 | { 10 | for(j=0;j<1001;j++) 11 | { 12 | if(i==j) 13 | dist[i][j]=0; 14 | else 15 | dist[i][j]=1001; 16 | } 17 | } 18 | cin>>n>>m; 19 | for(i=1;i<=m;i++) 20 | { 21 | cin>>u>>v>>wt; 22 | dist[u][v]=wt; 23 | dist[v][u]=wt; 24 | } 25 | for(k=1;k<=n;k++) 26 | { 27 | for(i=1;i<=n;i++) 28 | { 29 | for(j=1;j<=n;j++) 30 | { 31 | if((dist[i][k]!=1001)&&(dist[k][j]!=1001)&&(dist[i][j]>(dist[i][k]+dist[k][j]))) 32 | dist[i][j]=dist[i][k]+dist[k][j]; 33 | } 34 | } 35 | } 36 | for(i=1;i<=n;i++) 37 | { 38 | for(j=1;j<=n;j++) 39 | { 40 | if(dist[i][j]!=1001) 41 | cout<& gas, vector& cost) { 48 | int size=gas.size(); 49 | int sum=0; 50 | int res=0; 51 | int total=0; 52 | for(int i=0; i& ratings) { 4 | int sum =0; 5 | vector c (ratings.size(), 1); 6 | for (int i=1;iratings[i-1]) 8 | c[i] = c[i-1]+1; 9 | 10 | for(int i=ratings.size()-2;~i;i--) 11 | if(ratings[i]>ratings[i+1]) c[i] = max(c[i], c[i+1]+1); 12 | 13 | for(auto i: c) sum +=i; 14 | return sum; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /C++ Programs/Greedy/1561. Max_Coins_You_Can_Get.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem Link : https://leetcode.com/problems/maximum-number-of-coins-you-can-get/ 3 | 1561. Maximum Number of Coins You Can Get 4 | There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows: 5 | 6 | In each step, you will choose any 3 piles of coins (not necessarily consecutive). 7 | Of your choice, Alice will pick the pile with the maximum number of coins. 8 | You will pick the next pile with maximum number of coins. 9 | Your friend Bob will pick the last pile. 10 | Repeat until there are no more piles of coins. 11 | Given an array of integers piles where piles[i] is the number of coins in the ith pile. 12 | 13 | Return the maximum number of coins which you can have. 14 | 15 | 16 | 17 | Example 1: 18 | 19 | Input: piles = [2,4,1,2,7,8] 20 | Output: 9 21 | Explanation: Choose the triplet (2, 7, 8), Alice Pick the pile with 8 coins, you the pile with 7 coins and Bob the last one. 22 | Choose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one. 23 | The maximum number of coins which you can have are: 7 + 2 = 9. 24 | On the other hand if we choose this arrangement (1, 2, 8), (2, 4, 7) you only get 2 + 4 = 6 coins which is not optimal. 25 | Example 2: 26 | 27 | Input: piles = [2,4,5] 28 | Output: 4 29 | Example 3: 30 | 31 | Input: piles = [9,8,7,6,5,1,2,3,4] 32 | Output: 18 33 | 34 | 35 | Constraints: 36 | 37 | 3 <= piles.length <= 10^5 38 | piles.length % 3 == 0 39 | 1 <= piles[i] <= 10^4 40 | */ 41 | 42 | class Solution { 43 | public: 44 | int maxCoins(vector& piles) { 45 | sort(piles.begin(),piles.end(),greater()); 46 | int mx = 0, cnt = 0; 47 | while(cnt 6 | using namespace std; 7 | 8 | // heapify function to swap values to make a max heap binary tree (Tree in which the root element will be larger than child nodes). 9 | void heapify(int ar[],int n,int i){ 10 | int largest=i; 11 | // Left and right child of tree when arranged as tree from array 12 | int left=2*i+1; 13 | int right=2*i+2; 14 | if(ar[left]>ar[largest] && leftar[largest] && right=0;--i){ 31 | heapify(ar,n,i); 32 | } 33 | 34 | // Swap 0th element to last element as 0th will be largest value according to max heap tree and run heapify again except on swapped element, Hence array will be sorted. 35 | for(int i=n-1;i>=0;--i){ 36 | swap(ar[0],ar[i]); 37 | heapify(ar,i,0); 38 | } 39 | } 40 | 41 | //Sorting Algorithm Boiler code to take input of array, call the sorting function and print the array. 42 | int main(){ 43 | cout<<"Enter size of array : "; 44 | int size; 45 | cin>>size; 46 | int ar[size]; 47 | for(int i=0;i>ar[i]; 50 | } 51 | cout<<"Before Sort : "< 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | bool vis[100001]; 8 | vectoradj[100001]; 9 | vectoradjt[100001]; 10 | stackst; 11 | void DFS(int n); 12 | void DFSt(int n); 13 | int main() 14 | { 15 | int i, m, n, u, v; 16 | cin>>n>>m; 17 | memset(vis, false, sizeof(vis)); 18 | for(i=1;i<=m;i++) 19 | { 20 | cin>>u>>v; 21 | adj[u].push_back(v); 22 | adjt[v].push_back(u); 23 | } 24 | for(i=1;i<=n;i++) 25 | { 26 | if(vis[i]==false) 27 | DFS(i); 28 | } 29 | memset(vis, false, sizeof(vis)); 30 | while(st.empty()==0) 31 | { 32 | if(vis[st.top()]==false) 33 | { 34 | DFSt(st.top()); 35 | cout< 3 | using namespace std; 4 | 5 | int maxSubArraySum(int a[], int size) 6 | { 7 | int max_so_far = INT_MIN, max_ending_here = 0; 8 | 9 | for (int i = 0; i < size; i++) { 10 | max_ending_here = max_ending_here + a[i]; 11 | if (max_so_far < max_ending_here) 12 | max_so_far = max_ending_here; 13 | 14 | if (max_ending_here < 0) 15 | max_ending_here = 0; 16 | } 17 | return max_so_far; 18 | } 19 | 20 | int main() 21 | { 22 | int a[] = { -2, -3, 4, -1, -2, 1, 5, -3 }; 23 | int n = sizeof(a) / sizeof(a[0]); 24 | 25 | // Function Call 26 | int max_sum = maxSubArraySum(a, n); 27 | cout << "Maximum contiguous sum is " << max_sum; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C++ Programs/PascalTriangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // See https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/ 5 | // for details of this function 6 | int binomialCoeff(int n, int k); 7 | 8 | // Function to print first 9 | // n lines of Pascal's 10 | // Triangle 11 | void printPascal(int n) 12 | { 13 | // Iterate through every line and 14 | // print entries in it 15 | for (int line = 0; line < n; line++) 16 | { 17 | // Every line has number of 18 | // integers equal to line 19 | // number 20 | for (int i = 0; i <= line; i++) 21 | cout <<" "<< binomialCoeff(line, i); 22 | cout <<"\n"; 23 | } 24 | } 25 | 26 | // See https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/ 27 | // for details of this function 28 | int binomialCoeff(int n, int k) 29 | { 30 | int res = 1; 31 | if (k > n - k) 32 | k = n - k; 33 | for (int i = 0; i < k; ++i) 34 | { 35 | res *= (n - i); 36 | res /= (i + 1); 37 | } 38 | 39 | return res; 40 | } 41 | 42 | // Driver program 43 | int main() 44 | { 45 | int n = 7; 46 | printPascal(n); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++ Programs/Quick-sort.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program for counting sort 2 | #include 3 | #include 4 | using namespace std; 5 | #define RANGE 255 6 | 7 | // The main function that sort 8 | // the given string arr[] in 9 | // alphabetical order 10 | void countSort(char arr[]) 11 | { 12 | // The output character array 13 | // that will have sorted arr 14 | char output[strlen(arr)]; 15 | 16 | // Create a count array to store count of individual 17 | // characters and initialize count array as 0 18 | int count[RANGE + 1], i; 19 | memset(count, 0, sizeof(count)); 20 | 21 | // Store count of each character 22 | for (i = 0; arr[i]; ++i) 23 | ++count[arr[i]]; 24 | 25 | // Change count[i] so that count[i] now contains actual 26 | // position of this character in output array 27 | for (i = 1; i <= RANGE; ++i) 28 | count[i] += count[i - 1]; 29 | 30 | // Build the output character array 31 | for (i = 0; arr[i]; ++i) { 32 | output[count[arr[i]] - 1] = arr[i]; 33 | --count[arr[i]]; 34 | } 35 | 36 | /* 37 | For Stable algorithm 38 | for (i = sizeof(arr)-1; i>=0; --i) 39 | { 40 | output[count[arr[i]]-1] = arr[i]; 41 | --count[arr[i]]; 42 | } 43 | 44 | For Logic : See implementation 45 | */ 46 | 47 | // Copy the output array to arr, so that arr now 48 | // contains sorted characters 49 | for (i = 0; arr[i]; ++i) 50 | arr[i] = output[i]; 51 | } 52 | 53 | // Driver code 54 | int main() 55 | { 56 | char arr[] = "geeksforgeeks"; 57 | 58 | countSort(arr); 59 | 60 | cout << "Sorted character array is " << arr; 61 | return 0; 62 | } 63 | 64 | // This code is contributed by rathbhupendra 65 | -------------------------------------------------------------------------------- /C++ Programs/README.md: -------------------------------------------------------------------------------- 1 | # Upload any of your interesting C++ Programs here. 2 | ### Please avoid Spam and Invalid submissions 3 | -------------------------------------------------------------------------------- /C++ Programs/String-is-palindrome-or-not: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | string isPalindrome(string S) 6 | { 7 | 8 | for (int i = 0; i < S.length() / 2; i++) { 9 | 10 | 11 | if (S[i] != S[S.length() - i - 1]) { 12 | 13 | return "No"; 14 | } 15 | } 16 | 17 | return "Yes"; 18 | } 19 | 20 | 21 | int main() 22 | { 23 | string S = "ABCDCBA"; 24 | cout << isPalindrome(S); 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++ Programs/TravellingSalseman.cpp: -------------------------------------------------------------------------------- 1 | // CPP program to implement traveling salesman 2 | // problem using naive approach. 3 | #include 4 | using namespace std; 5 | #define V 4 6 | 7 | // implementation of traveling Salesman Problem 8 | int travllingSalesmanProblem(int graph[][V], int s) 9 | { 10 | // store all vertex apart from source vertex 11 | vector vertex; 12 | for (int i = 0; i < V; i++) 13 | if (i != s) 14 | vertex.push_back(i); 15 | 16 | // store minimum weight Hamiltonian Cycle. 17 | int min_path = INT_MAX; 18 | do { 19 | 20 | // store current Path weight(cost) 21 | int current_pathweight = 0; 22 | 23 | // compute current path weight 24 | int k = s; 25 | for (int i = 0; i < vertex.size(); i++) { 26 | current_pathweight += graph[k][vertex[i]]; 27 | k = vertex[i]; 28 | } 29 | current_pathweight += graph[k][s]; 30 | 31 | // update minimum 32 | min_path = min(min_path, current_pathweight); 33 | 34 | } while ( 35 | next_permutation(vertex.begin(), vertex.end())); 36 | 37 | return min_path; 38 | } 39 | 40 | // Driver Code 41 | int main() 42 | { 43 | // matrix representation of graph 44 | int graph[][V] = { { 0, 10, 15, 20 }, 45 | { 10, 0, 35, 25 }, 46 | { 15, 35, 0, 30 }, 47 | { 20, 25, 30, 0 } }; 48 | int s = 0; 49 | cout << travllingSalesmanProblem(graph, s) << endl; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /C++ Programs/ans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int getPairsCount(int arr[], int n, int sum) 5 | { 6 | unordered_map m; 7 | 8 | // Store counts of all elements in map m 9 | for (int i = 0; i < n; i++) 10 | m[arr[i]]++; 11 | 12 | int twice_count = 0; 13 | 14 | // iterate through each element and increment the 15 | // count (Notice that every pair is counted twice) 16 | for (int i = 0; i < n; i++) { 17 | twice_count += m[sum - arr[i]]; 18 | 19 | // if (arr[i], arr[i]) pair satisfies the condition, 20 | // then we need to ensure that the count is 21 | // decreased by one such that the (arr[i], arr[i]) 22 | // pair is not considered 23 | if (sum - arr[i] == arr[i]) 24 | twice_count--; 25 | } 26 | 27 | // return the half of twice_count 28 | return twice_count / 2; 29 | } 30 | 31 | int main(){ 32 | int arr[] = {7,3,9,12,7}; 33 | int x = 14; 34 | cout< 2 | using namespace std; 3 | const int N = 1e5 + 10; 4 | vector g[N]; 5 | bool vis[N]; 6 | void dfs(int vertex){ 7 | vis[vertex] = true; 8 | for(int child:g[vertex]){ 9 | if(vis[child]) continue; 10 | dfs(child); 11 | } 12 | } 13 | int main() { 14 | int n,e; 15 | cin>>n>>e; 16 | for(int i=0;i>x>>y;-g[x].push_back(y); 19 | g[y].push_back(x); 20 | 21 | } 22 | int ct =0; 23 | for(int i=1;i<=n;i++){ 24 | if(vis[i]) continue; 25 | dfs(i); 26 | ct++; 27 | } 28 | cout< 4 | using namespace std; 5 | 6 | /* Link list node */ 7 | struct Node { 8 | int data; 9 | Node* next; 10 | }; 11 | 12 | void push(Node** head_ref, int new_data); 13 | 14 | /*This solution uses the temporary 15 | dummy to build up the result list */ 16 | Node* sortedIntersect(Node* a, Node* b) 17 | { 18 | Node dummy; 19 | Node* tail = &dummy; 20 | dummy.next = NULL; 21 | 22 | /* Once one or the other 23 | list runs out -- we're done */ 24 | while (a != NULL && b != NULL) { 25 | if (a->data == b->data) { 26 | push((&tail->next), a->data); 27 | tail = tail->next; 28 | a = a->next; 29 | b = b->next; 30 | } 31 | /* advance the smaller list */ 32 | else if (a->data < b->data) 33 | a = a->next; 34 | else 35 | b = b->next; 36 | } 37 | return (dummy.next); 38 | } 39 | 40 | /* UTILITY FUNCTIONS */ 41 | /* Function to insert a node at 42 | the beginning of the linked list */ 43 | void push(Node** head_ref, int new_data) 44 | { 45 | /* allocate node */ 46 | Node* new_node = (Node*)malloc( 47 | sizeof(Node)); 48 | 49 | /* put in the data */ 50 | new_node->data = new_data; 51 | 52 | /* link the old list off the new node */ 53 | new_node->next = (*head_ref); 54 | 55 | /* move the head to point to the new node */ 56 | (*head_ref) = new_node; 57 | } 58 | 59 | /* Function to print nodes in 60 | a given linked list */ 61 | void printList(Node* node) 62 | { 63 | while (node != NULL) { 64 | cout << node->data <<" "; 65 | node = node->next; 66 | } 67 | } 68 | 69 | /* Driver program to test above functions*/ 70 | int main() 71 | { 72 | /* Start with the empty lists */ 73 | Node* a = NULL; 74 | Node* b = NULL; 75 | Node* intersect = NULL; 76 | 77 | /* Let us create the first sorted 78 | linked list to test the functions 79 | Created linked list will be 80 | 1->2->3->4->5->6 */ 81 | push(&a, 6); 82 | push(&a, 5); 83 | push(&a, 4); 84 | push(&a, 3); 85 | push(&a, 2); 86 | push(&a, 1); 87 | 88 | /* Let us create the second sorted linked list 89 | Created linked list will be 2->4->6->8 */ 90 | push(&b, 8); 91 | push(&b, 6); 92 | push(&b, 4); 93 | push(&b, 2); 94 | 95 | /* Find the intersection two linked lists */ 96 | intersect = sortedIntersect(a, b); 97 | 98 | cout<<"Linked list containing common items of a & b \n"; 99 | printList(intersect); 100 | } 101 | -------------------------------------------------------------------------------- /C++ Programs/linear_search.cpp: -------------------------------------------------------------------------------- 1 | // C++ Recursive Code For Linear Search 2 | #include 3 | using namespace std; 4 | 5 | int linearsearch(int arr[], int size, int key) 6 | { 7 | if (size == 0) { 8 | return -1; 9 | } 10 | else if (arr[size - 1] == key) { 11 | // Return the index of found key. 12 | return size - 1; 13 | } 14 | else { 15 | int ans = linearsearch(arr, size - 1, key); 16 | return ans; 17 | } 18 | } 19 | 20 | // Driver's Code 21 | int main() 22 | { 23 | int arr[5] = {5, 15, 6, 9, 4 }; 24 | int key = 4; 25 | 26 | // Function call 27 | int ans = linearsearch(arr, 5, key); 28 | if (ans == -1) { 29 | cout << "The element " << key << " is not found." 30 | << endl; 31 | } 32 | else { 33 | cout << "The element " << key << " is found at " 34 | << ans << " index of the given array." << endl; 35 | } 36 | return 0; 37 | } 38 | // Code contributed by pragatikohli 39 | -------------------------------------------------------------------------------- /C++ Programs/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Function to check whether string 5 | // is palindrome 6 | string isPalindrome(string S) 7 | { 8 | // Iterate over the range [0, N/2] 9 | for (int i = 0; i < S.length() / 2; i++) { 10 | 11 | // If S[i] is not equal to 12 | // the S[N-i-1] 13 | if (S[i] != S[S.length() - i - 1]) { 14 | // Return No 15 | return "No"; 16 | } 17 | } 18 | // Return "Yes" 19 | return "Yes"; 20 | } 21 | 22 | // Driver Code 23 | int main() 24 | { 25 | string S = "ABCDCBA"; 26 | cout << isPalindrome(S); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C++ Programs/reverseLinkedList.cpp: -------------------------------------------------------------------------------- 1 | // Iterative C++ program to reverse a linked list 2 | #include 3 | using namespace std; 4 | 5 | /* Link list node */ 6 | struct Node { 7 | int data; 8 | struct Node* next; 9 | Node(int data) 10 | { 11 | this->data = data; 12 | next = NULL; 13 | } 14 | }; 15 | 16 | struct LinkedList { 17 | Node* head; 18 | LinkedList() { head = NULL; } 19 | 20 | /* Function to reverse the linked list */ 21 | void reverse() 22 | { 23 | // Initialize current, previous and next pointers 24 | Node* current = head; 25 | Node *prev = NULL, *next = NULL; 26 | 27 | while (current != NULL) { 28 | // Store next 29 | next = current->next; 30 | // Reverse current node's pointer 31 | current->next = prev; 32 | // Move pointers one position ahead. 33 | prev = current; 34 | current = next; 35 | } 36 | head = prev; 37 | } 38 | 39 | /* Function to print linked list */ 40 | void print() 41 | { 42 | struct Node* temp = head; 43 | while (temp != NULL) { 44 | cout << temp->data << " "; 45 | temp = temp->next; 46 | } 47 | } 48 | 49 | void push(int data) 50 | { 51 | Node* temp = new Node(data); 52 | temp->next = head; 53 | head = temp; 54 | } 55 | }; 56 | 57 | /* Driver code*/ 58 | int main() 59 | { 60 | /* Start with the empty list */ 61 | LinkedList ll; 62 | ll.push(20); 63 | ll.push(4); 64 | ll.push(15); 65 | ll.push(85); 66 | 67 | cout << "Given linked list\n"; 68 | ll.print(); 69 | 70 | ll.reverse(); 71 | 72 | cout << "\nReversed Linked list \n"; 73 | ll.print(); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /C++ Programs/runTimePolymorphism.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A{ 4 | protected: 5 | int var; 6 | int x; 7 | int y; 8 | public: 9 | void setVal(int v){ 10 | var=v; 11 | } 12 | void getVal(){ 13 | cout<<"The Value of the Variable is : "<setVal(4); 33 | base->getVal(); 34 | 35 | B *b; 36 | B b1; 37 | b = &b1; 38 | b->setVal(435,345); 39 | b->getVal(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /C++ Programs/size: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | cout << "Size of char: " << sizeof(char) << " byte" << endl; 7 | cout << "Size of int: " << sizeof(int) << " bytes" << endl; 8 | cout << "Size of float: " << sizeof(float) << " bytes" << endl; 9 | cout << "Size of double: " << sizeof(double) << " bytes" << endl; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /C++ Programs/twosum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector twoSum(vector& nums, int target) { 4 | vector arr; 5 | for(int i=0;i* { 8 | padding-right: 0; 9 | padding-left: 0; 10 | } 11 | 12 | .count-input { 13 | float: right; 14 | margin-top: 0.7em; 15 | } 16 | 17 | .count-input .input-number { 18 | text-align: center; 19 | width: 5em; 20 | } 21 | 22 | .amount-article-form .btn{ 23 | font-weight: 900; 24 | color: white; 25 | font-size: 1.5em; 26 | line-height: 1em; 27 | width: 2em; 28 | } 29 | 30 | div.card.mb-3 { 31 | max-width: 31%; 32 | margin: 0.5rem; 33 | } 34 | 35 | div.card.mb-3 img.big { 36 | width: 100%; 37 | display: block; 38 | } 39 | 40 | div.card.mb-3 img.small { 41 | height: 4em; 42 | float: left; 43 | } 44 | 45 | .co-img { 46 | height: 2em 47 | } 48 | 49 | .co-btn { 50 | position: fixed; 51 | top: 1em; 52 | right: 1em; 53 | z-index: 20; 54 | } 55 | 56 | .co-btn-img { 57 | margin-right: 0.5em; 58 | filter: invert(100%); 59 | height: 1em; 60 | } 61 | 62 | .buy-more-btn { 63 | position: fixed; 64 | top: 1em; 65 | right: 1em; 66 | z-index: 20; 67 | } 68 | 69 | .buy-more-btn-img { 70 | margin-right: 0.5em; 71 | filter: invert(100%); 72 | height: 1em; 73 | } -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/bacon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/bacon.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/crinklefries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/crinklefries.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/fryingfat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/fryingfat.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/garlic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/garlic.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/icecream.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/icecream.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/oliveoil.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/oliveoil.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/shrimps.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/shrimps.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/steakhousefries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/steakhousefries.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/sweetpotatoefries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/sweetpotatoefries.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/products/tortilla.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/resources/public/img/products/tortilla.jpg -------------------------------------------------------------------------------- /Clojure Programs/Webshop/resources/public/img/shopping-cart.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/src/metro/components/db/postgres.clj: -------------------------------------------------------------------------------- 1 | (ns metro.components.db.postgres 2 | (:require [com.stuartsierra.component :as component] 3 | [korma.db :as kdb] 4 | [metro.components.db.articles :as articles])) 5 | 6 | (def status (atom "down")) 7 | 8 | (defrecord Postgres [db-config database] 9 | component/Lifecycle 10 | (start [this] 11 | (let [db (kdb/create-db (kdb/postgres db-config))] 12 | (kdb/default-connection db) 13 | (articles/create-table! false) 14 | (assoc this :database db)) 15 | (reset! status "up")) 16 | (stop [this] 17 | (kdb/default-connection nil) 18 | (assoc this :database nil) 19 | (reset! status "down"))) 20 | 21 | (defn new-database [] 22 | (map->Postgres {})) 23 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/src/metro/components/server/pedestal.clj: -------------------------------------------------------------------------------- 1 | (ns metro.components.server.pedestal 2 | (:require [com.stuartsierra.component :as component] 3 | [io.pedestal.http :as http])) 4 | 5 | (defn test? [service-map] 6 | (= :test (:env service-map))) 7 | 8 | (def status (atom "down")) 9 | 10 | (defrecord Pedestal [service-map service] 11 | component/Lifecycle 12 | (start [this] 13 | (reset! status "up") 14 | (if service 15 | this 16 | (cond-> service-map 17 | true (http/create-server) ;; always create http server 18 | (not (test? service-map)) (http/start) ;; start http server if not in testing environment 19 | true (partial assoc this :service)))) 20 | (stop [this] 21 | (when (and service (not (test? service-map))) 22 | (http/stop service)) 23 | (assoc this :service nil) 24 | (reset! status "down"))) 25 | 26 | (defn new-pedestal [] 27 | (map->Pedestal {})) 28 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/src/metro/components/server/routes.clj: -------------------------------------------------------------------------------- 1 | (ns metro.components.server.routes 2 | (:require [io.pedestal.http :as http] 3 | [io.pedestal.http.body-params :as body-params] 4 | [io.pedestal.interceptor :refer [interceptor]] 5 | [metro.components.web.health :as health] 6 | [metro.components.web.views :as views] 7 | [metro.components.web.api :as api] 8 | [io.pedestal.http.route :as route])) 9 | 10 | (def common-interceptors 11 | ;; Parsing the body parameters according to the request’s content-type header. 12 | [(body-params/body-params) http/html-body]) 13 | 14 | (def routes 15 | ;; Routes are a set of different rules. 16 | #{["/" :get (conj common-interceptors `views/shop) :route-name :index] 17 | ["/greet" :get views/respond-hello :route-name :greet] 18 | ["/health" :get (conj common-interceptors `health/health) :route-name :health] 19 | ["/checkout" :get (conj common-interceptors `views/checkout) :route-name :checkout] 20 | ["/article/inc" :post (conj common-interceptors `views/inc-article) :route-name :inc-article] 21 | ["/article/dec" :post (conj common-interceptors `views/dec-article) :route-name :dec-article] 22 | ["/article/rem" :post (conj common-interceptors `views/rem-article) :route-name :rem-article] 23 | ["/api/greet" :get api/respond-hello :route-name :api-greet] 24 | ["/api/article/all" :get (conj common-interceptors `api/all-article) :route-name :api-all-article] 25 | ["/api/article/inc" :post (conj common-interceptors `api/inc-article) :route-name :api-inc-article] 26 | ["/api/article/dec" :post (conj common-interceptors `api/dec-article) :route-name :api-dec-article] 27 | ["/api/article/rem" :post (conj common-interceptors `api/rem-article) :route-name :api-rem-article] 28 | ["/api/basket" :get (conj common-interceptors `api/basket) :route-name :api-basket]}) 29 | 30 | (def url-for 31 | ;; Helper function for unit tests 32 | (route/url-for-routes (route/expand-routes routes))) 33 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/src/metro/components/web/api.clj: -------------------------------------------------------------------------------- 1 | (ns metro.components.web.api 2 | (:require [clojure.data.json :as json] 3 | [ring.util.response :refer [response]] 4 | [metro.components.db.articles :as article])) 5 | 6 | (defn respond-hello [request] 7 | (let [name (get-in request [:query-params :name]) 8 | resp (if (empty? name) "Hello, world!" (str "Hello, " name "!"))] 9 | {:status 200 :body resp})) 10 | 11 | 12 | (defn all-article [_] 13 | {:status 200 14 | :headers {"Content-Type" "application/json"} 15 | :body (json/write-str {:articles (sort-by :title (article/query-all))})}) 16 | 17 | (defn basket [_] 18 | {:status 200 19 | :headers {"Content-Type" "application/json"} 20 | :body (json/write-str {:articles (article/query-all-with-count)})}) 21 | 22 | (defn- article [id] 23 | {:status 200 24 | :headers {"Content-Type" "application/json"} 25 | :body (json/write-str {:id id 26 | :articles (article/query-all)})}) 27 | 28 | (defn inc-article [{:keys [form-params]}] 29 | (article/inc! (:id form-params)) 30 | (article (:id form-params))) 31 | 32 | (defn dec-article [{:keys [form-params]}] 33 | (article/dec! (:id form-params)) 34 | (article (:id form-params))) 35 | 36 | (defn rem-article [{:keys [form-params]}] 37 | (article/rem! (:id form-params)) 38 | (all-article "")) 39 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/src/metro/components/web/health.clj: -------------------------------------------------------------------------------- 1 | (ns metro.components.web.health 2 | (:require [clojure.data.json :as json] 3 | [metro.components.server.pedestal :as server] 4 | [metro.components.db.postgres :as postgres])) 5 | 6 | (defn health [request] 7 | {:status 200 8 | :headers {"Content-Type" "application/json"} 9 | :body (json/write-str {:server @server/status 10 | :database @postgres/status})}) -------------------------------------------------------------------------------- /Clojure Programs/Webshop/src/metro/components/web/views.clj: -------------------------------------------------------------------------------- 1 | (ns metro.components.web.views 2 | (:require [ring.util.response :as ring-resp] 3 | [metro.components.db.articles :as article] 4 | [metro.components.web.api :as api] 5 | [metro.components.web.blocks :as blocks])) 6 | 7 | (defn shop [_] 8 | (blocks/base-template 9 | [:h1.center "Amazing Web Shop Application"] 10 | (blocks/button->checkout) 11 | [:hr {:style "margin: 2rem 0"}] 12 | [:div.row {:style "margin: 0; padding-left: 1em;"} 13 | (vec (conj (blocks/article->big-cards) :tbody))] 14 | (blocks/text->pizza))) 15 | 16 | (defn checkout [_] 17 | (blocks/base-template 18 | [:h1.center "Checkout"] 19 | (blocks/checkout-table) 20 | (blocks/button->buy-more) 21 | (blocks/text->pizza))) 22 | 23 | (defn inc-article [{:keys [form-params]}] 24 | (article/inc! (:id form-params)) 25 | (ring-resp/redirect "/")) 26 | 27 | (defn dec-article [{:keys [form-params]}] 28 | (article/dec! (:id form-params)) 29 | (ring-resp/redirect "/")) 30 | 31 | (defn rem-article [request] 32 | (api/rem-article request) 33 | (ring-resp/redirect "/checkout")) 34 | 35 | (defn respond-hello [request] 36 | (let [name (get-in request [:query-params :name]) 37 | resp (cond (empty? name) "Hello, world!" 38 | :else (str "Hello, " name "!"))] 39 | {:status 200 :body resp})) -------------------------------------------------------------------------------- /Clojure Programs/Webshop/src/metro/system.clj: -------------------------------------------------------------------------------- 1 | (ns metro.system 2 | (:gen-class) 3 | (:require [com.stuartsierra.component :as component] 4 | [io.pedestal.http :as http] 5 | [metro.components.server.pedestal :as pedestal] 6 | [metro.components.server.routes :as routes] 7 | [metro.components.db.postgres :as postgres])) 8 | 9 | (defn- build-service-map [env] 10 | ;; Pedestals web server configuration (http://pedestal.io/reference/service-map). 11 | {:env env 12 | ;; Routes can be a function that resolve routes 13 | ::http/routes routes/routes 14 | ;; Define server type 15 | ::http/type :jetty 16 | ;; Is it docker or local? 17 | ::http/host (or (System/getenv "WEB_HOST") "localhost") 18 | ;; Port to listen on 19 | ::http/port 8080 20 | ;; Path of public resources 21 | ::http/resource-path "/public" 22 | ;; All origins are allowed in dev mode 23 | ::http/allowed-origins {:creds true :allowed-origins (constantly true)} 24 | ;; Content Security Policy (CSP) is mostly turned off in dev mode 25 | ::http/secure-headers {:content-security-policy-settings {:object-src "'none'"}} 26 | }) 27 | 28 | (defn system [env] 29 | ;; Passing components to the main system 30 | (component/system-map 31 | :service-map (build-service-map env) 32 | :db-config {:db "clojure" 33 | :user "clojure" 34 | :password "clojure" 35 | :host (or (System/getenv "DB_HOST") "localhost")} 36 | :db (component/using (postgres/new-database) [:db-config]) 37 | :web (component/using (pedestal/new-pedestal) [:db :service-map]))) 38 | 39 | (defn -main [& _] 40 | (component/start (system {}))) 41 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/target/.DS_Store -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/default+repl/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/target/default+repl/.DS_Store -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/default+repl/classes/META-INF/maven/metro/metro/pom.properties: -------------------------------------------------------------------------------- 1 | groupId=metro 2 | artifactId=metro 3 | version=0.0.1-SNAPSHOT 4 | revision=acedaceae794b8c9bd0805356880169e19a66b86 5 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/default+repl/repl-port: -------------------------------------------------------------------------------- 1 | 37657 -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/default+test+test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/target/default+test+test/.DS_Store -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/default+test+test/classes/META-INF/maven/metro/metro/pom.properties: -------------------------------------------------------------------------------- 1 | version=0.0.1-SNAPSHOT 2 | revision=dc57eecb19e09583cb5f08b65cbe0f01ceb87cf5 3 | groupId=metro 4 | artifactId=metro 5 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/default/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/target/default/.DS_Store -------------------------------------------------------------------------------- /Clojure Programs/Webshop/target/default/classes/META-INF/maven/metro/metro/pom.properties: -------------------------------------------------------------------------------- 1 | version=0.0.1-SNAPSHOT 2 | revision=acedaceae794b8c9bd0805356880169e19a66b86 3 | groupId=metro 4 | artifactId=metro 5 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/test/.DS_Store -------------------------------------------------------------------------------- /Clojure Programs/Webshop/test/metro/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/test/metro/.DS_Store -------------------------------------------------------------------------------- /Clojure Programs/Webshop/test/metro/system_test.clj: -------------------------------------------------------------------------------- 1 | (ns metro.system-test 2 | (:require [io.pedestal.http :as http] 3 | [io.pedestal.test :refer [response-for]] 4 | [com.stuartsierra.component :as component] 5 | [clojure.test :refer [deftest is are testing]] 6 | [korma.db :as kdb] 7 | [metro.system :as system] 8 | [metro.components.db.articles :as articles])) 9 | 10 | (defrecord TestDB [db-config database] 11 | component/Lifecycle 12 | (start [this] 13 | (let [db (kdb/create-db (kdb/sqlite3 {:db "testing.sqlite3"}))] 14 | (kdb/default-connection db) 15 | (articles/drop-table!) 16 | (articles/create-table! true) 17 | (assoc this :database db))) 18 | (stop [this] 19 | ;(articles/drop-table!) 20 | (kdb/default-connection nil) 21 | (assoc this :database nil))) 22 | 23 | (def system 24 | (assoc (system/system :test) 25 | :db (map->TestDB {}))) ;; Inject TestDB for testing 26 | 27 | (defmacro with-system 28 | [[bound-var test-system] & body] 29 | `(let [~bound-var (component/start ~test-system)] 30 | (try 31 | ~@body 32 | (finally 33 | (component/stop ~bound-var))))) 34 | 35 | (defn service-fn 36 | [system] 37 | (get-in system [:web :service ::http/service-fn])) 38 | 39 | (comment 40 | (def my-test-system (component/start system)) 41 | my-test-system) 42 | -------------------------------------------------------------------------------- /Clojure Programs/Webshop/testing.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/Clojure Programs/Webshop/testing.sqlite3 -------------------------------------------------------------------------------- /Java Programs/CheckForElement.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class CheckForElement { 4 | public static void main(String[] args) { 5 | int[] arr = {1,2,3,34,4,5,9,0}; 6 | int x = 34; 7 | System.out.println(check(arr, arr.length, x)); 8 | System.out.println(check(arr, arr.length, x)); 9 | } 10 | 11 | private static boolean check(int[] arr, int n, int x) { 12 | if (n==1){ 13 | if (arr[0] == x) return true; 14 | return false; 15 | } 16 | 17 | if (arr[n-1] == x) return true; 18 | return check(arr, n-1, x); 19 | } 20 | 21 | private static boolean check2(int[] arr, int s, int x){ 22 | if (s== arr.length-1){ 23 | if (arr[0] == x) return true; 24 | return false; 25 | } 26 | 27 | if (arr[s] == x) return true; 28 | return check2(arr, s+1,x); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Java Programs/CheckSortedArray.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class CheckSortedArray { 4 | public static void main(String[] args) { 5 | int[] arr = {3,2}; 6 | System.out.println(isSorted2(arr, 0)); 7 | } 8 | 9 | static boolean isSorted(int[] arr, int n) { 10 | if (n==0 || n==1) return true; 11 | if (arr[n-2] > arr[n-1]) return false; 12 | return isSorted(arr, n-1); 13 | } 14 | 15 | static boolean isSorted2(int[] arr, int i){ 16 | if (i == arr.length-1) return true; 17 | if (arr[i+1] > arr[i]) return isSorted2(arr, i+1); 18 | return false; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Java Programs/Combinations.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | // LEETCODE QUESTION https://leetcode.com/problems/combinations/ 3 | // print all combinations of nCr 4 | // example arr = {1,2,3} print 4C2 5 | // output: {1,2}, {2,3}, {1,3} 6 | 7 | 8 | import java.util.ArrayList; 9 | 10 | public class Combinations { 11 | public static void main(String[] args) { 12 | int[] nums = {1,2,3,4,5,6,7}; 13 | combination(nums, 0, new ArrayList<>(), nums.length, 2); 14 | } 15 | 16 | public static void combination(int[] arr, int i, ArrayList ll, int n, int r){ 17 | if (i>=n){ 18 | if (ll.size() == r){ 19 | System.out.println(ll); 20 | } 21 | return; 22 | } 23 | ll.add(arr[i]); 24 | combination(arr, i+1, ll, n, r); 25 | ll.remove(ll.size()-1); 26 | combination(arr, i+1, ll, n, r); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Java Programs/CountDigits.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class CountDigits { 4 | public static void main(String[] args) { 5 | System.out.println(count(123)); 6 | } 7 | 8 | static int count(int n){ 9 | if (n==0) return 0; 10 | return 1 + count(n/10); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Java Programs/CountFreq.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Arrays; 4 | 5 | // counting the frequency of every element 6 | public class CountFreq { 7 | public static void main(String[] args) { 8 | int[] ans = getFreq(new int[] {1,1,2,2,3,3,3}); 9 | System.out.println(Arrays.toString(ans)); 10 | } 11 | 12 | public static int[] getFreq(int[] nums){ 13 | int[] arr =new int[101]; 14 | for (int i = 0; i < nums.length; i++) { 15 | int index = nums[i]; 16 | arr[index] = arr[index] + 1; 17 | } 18 | return arr; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Java Programs/Factorial.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class Factorial { 4 | public static void main(String[] args) { 5 | System.out.println(fact(5)); 6 | } 7 | 8 | static int fact(int x){ 9 | if (x == 0) return 1; 10 | if (x == 1) return 1; 11 | return x * fact(x - 1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java Programs/Factors: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | int number = 60; 5 | 6 | System.out.print("Factors of " + number + " are: "); 7 | for (int i = 1; i <= number; ++i) { 8 | if (number % i == 0) { 9 | System.out.print(i + " "); 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java Programs/FirstOccur.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class FirstOccur { 4 | public static void main(String[] args) { 5 | int[] arr = {1,2,3,4,5,7,8,9}; 6 | int x = 0; 7 | System.out.println(getIndex(arr, 0, x)); 8 | } 9 | 10 | private static int getIndex(int[] arr, int s, int x) { 11 | if (s<=arr.length-1){ 12 | if (x==arr[s]) return s; 13 | return -1; 14 | } 15 | if (x==arr[s]) return s; 16 | return getIndex(arr, s+1, x); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java Programs/GetIndices.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class GetIndices { 4 | public static void main(String[] args) { 5 | int[] arr = {9, 8, 10, 8, 8, 7}; 6 | int x = 0; 7 | getIndices(arr, 0, x); 8 | } 9 | 10 | private static void getIndices(int[] arr, int s, int x){ 11 | if (s >= arr.length) { 12 | System.out.println(-1); 13 | return; 14 | } 15 | if (arr[s] == x){ 16 | System.out.print(s + " "); 17 | } 18 | getIndices(arr, s+1, x); 19 | } 20 | 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Java Programs/HeapSort.java: -------------------------------------------------------------------------------- 1 | // Java program for implementation of Heap Sort 2 | 3 | 4 | public class HeapSort { 5 | 6 | public void sort(int arr[]) 7 | 8 | { 9 | 10 | int N = arr.length; 11 | 12 | 13 | // Build heap (rearrange array) 14 | 15 | for (int i = N / 2 - 1; i >= 0; i--) 16 | 17 | heapify(arr, N, i); 18 | 19 | 20 | // One by one extract an element from heap 21 | 22 | for (int i = N - 1; i > 0; i--) { 23 | 24 | // Move current root to end 25 | 26 | int temp = arr[0]; 27 | 28 | arr[0] = arr[i]; 29 | 30 | arr[i] = temp; 31 | 32 | 33 | // call max heapify on the reduced heap 34 | 35 | heapify(arr, i, 0); 36 | 37 | } 38 | 39 | } 40 | 41 | 42 | // To heapify a subtree rooted with node i which is 43 | 44 | // an index in arr[]. n is size of heap 45 | 46 | void heapify(int arr[], int N, int i) 47 | 48 | { 49 | 50 | int largest = i; // Initialize largest as root 51 | 52 | int l = 2 * i + 1; // left = 2*i + 1 53 | 54 | int r = 2 * i + 2; // right = 2*i + 2 55 | 56 | 57 | // If left child is larger than root 58 | 59 | if (l < N && arr[l] > arr[largest]) 60 | 61 | largest = l; 62 | 63 | 64 | // If right child is larger than largest so far 65 | 66 | if (r < N && arr[r] > arr[largest]) 67 | 68 | largest = r; 69 | 70 | 71 | // If largest is not root 72 | 73 | if (largest != i) { 74 | 75 | int swap = arr[i]; 76 | 77 | arr[i] = arr[largest]; 78 | 79 | arr[largest] = swap; 80 | 81 | 82 | // Recursively heapify the affected sub-tree 83 | 84 | heapify(arr, N, largest); 85 | 86 | } 87 | 88 | } 89 | 90 | 91 | /* A utility function to print array of size n */ 92 | 93 | static void printArray(int arr[]) 94 | 95 | { 96 | 97 | int N = arr.length; 98 | 99 | 100 | for (int i = 0; i < N; ++i) 101 | 102 | System.out.print(arr[i] + " "); 103 | 104 | System.out.println(); 105 | 106 | } 107 | 108 | 109 | // Driver's code 110 | 111 | public static void main(String args[]) 112 | 113 | { 114 | 115 | int arr[] = { 12, 11, 13, 5, 6, 7 }; 116 | 117 | int N = arr.length; 118 | 119 | 120 | // Function call 121 | 122 | HeapSort ob = new HeapSort(); 123 | 124 | ob.sort(arr); 125 | 126 | 127 | System.out.println("Sorted array is"); 128 | 129 | printArray(arr); 130 | 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Java Programs/KadaneAlgo.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class KadaneAlgo { 4 | public static void main(String[] args) { 5 | System.out.println(kadaneAlgo(new int[]{1,2,3,4,-10, 11, -1})); 6 | } 7 | 8 | public static int kadaneAlgo(int[] arr){ 9 | int max = arr[0], sum = 0; 10 | int len = 0; 11 | for (int i = 0; i < arr.length; i++) { 12 | sum+=arr[i]; 13 | len++; 14 | if (sum > max) { 15 | max = sum; 16 | } 17 | if (sum <= 0) { 18 | sum = 0; 19 | len = 0; 20 | } 21 | } 22 | return len; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Java Programs/LastOccur.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class LastOccur { 4 | public static void main(String[] args) { 5 | int[] arr = {1,2,4,5,0,3,9,4,6}; 6 | int x = 99; 7 | System.out.println(getLastIndex(arr, arr.length, x)); 8 | } 9 | 10 | private static int getLastIndex(int[] arr, int n, int x) { 11 | if (n==1){ 12 | if (arr[0] == x) return 0; 13 | return -1; 14 | } 15 | if (arr[n-1] == x) return arr.length - (n-1); 16 | return getLastIndex(arr, n-1, x); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java Programs/LeftRotate.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Arrays; 4 | 5 | public class LeftRotate { 6 | public static void main(String[] args) { 7 | int[][] arr = { 8 | {1,2,3,4}, 9 | {5,3,2,1}, 10 | {4,2,3,5} 11 | }; 12 | for (int i = 0; i < 12; i++) { 13 | if(i%4==0){ 14 | System.out.println(); 15 | } 16 | System.out.print(arr[i/4][i%4] + " "); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java Programs/MinMaxInTheArray.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class MinMaxInTheArray { 4 | public static void main(String[] args){ 5 | int[] arr = {1,2,3,4,5,6,7}; 6 | int ans = MinMax(arr, false); 7 | System.out.println(ans); 8 | } 9 | 10 | private static int MinMax(int[] arr, boolean max) { 11 | if(max){ 12 | int m = Integer.MIN_VALUE; 13 | for (int j : arr) { 14 | if (j > m) { 15 | m = j; 16 | } 17 | } 18 | return m; 19 | } 20 | else { 21 | int m = Integer.MAX_VALUE; 22 | // Math.log10(); 23 | for (int j : arr) { 24 | if (j < m) { 25 | m = j; 26 | } 27 | } 28 | return m; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Java Programs/MultiplyMatrices: -------------------------------------------------------------------------------- 1 | public class MultiplyMatrices { 2 | 3 | public static void main(String[] args) { 4 | int r1 = 2, c1 = 3; 5 | int r2 = 3, c2 = 2; 6 | int[][] firstMatrix = { {3, -2, 5}, {3, 0, 4} }; 7 | int[][] secondMatrix = { {2, 3}, {-9, 0}, {0, 4} }; 8 | 9 | int[][] product = new int[r1][c2]; 10 | for(int i = 0; i < r1; i++) { 11 | for (int j = 0; j < c2; j++) { 12 | for (int k = 0; k < c1; k++) { 13 | product[i][j] += firstMatrix[i][k] * secondMatrix[k][j]; 14 | } 15 | } 16 | } 17 | 18 | System.out.println("Multiplication of two matrices is: "); 19 | for(int[] row : product) { 20 | for (int column : row) { 21 | System.out.print(column + " "); 22 | } 23 | System.out.println(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java Programs/NumberGuessingGame.java: -------------------------------------------------------------------------------- 1 | package basics; 2 | 3 | import java.util.Scanner; 4 | 5 | public class NumberGuessingGame { 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | int myNumber = (int)(Math.random()*100); 10 | int userNumber = 0; 11 | 12 | do { 13 | System.out.println("Guess my Number: "); 14 | userNumber = sc.nextInt(); 15 | 16 | if(userNumber == myNumber) { 17 | System.out.println("WOOHOO..... CORRECT NUMBER!!!"); 18 | break; 19 | } 20 | else if(userNumber > myNumber) { 21 | System.out.println("Your number is too large"); 22 | } 23 | else { 24 | System.out.println("Your number is too small"); 25 | } 26 | } while(userNumber >= 0); 27 | 28 | System.out.print("My number was: "); 29 | System.out.println(myNumber); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Java Programs/Plaindrome.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Palindrome 3 | { 4 | public static void main(String args[]) 5 | { 6 | String original, reverse = ""; // Objects of String class 7 | Scanner in = new Scanner(System.in); 8 | System.out.println("Enter a string/number to check if it is a palindrome"); 9 | original = in.nextLine(); 10 | int length = original.length(); 11 | for ( int i = length - 1; i >= 0; i-- ) 12 | reverse = reverse + original.charAt(i); 13 | if (original.equals(reverse)) 14 | System.out.println("Entered string/number is a palindrome."); 15 | else 16 | System.out.println("Entered string/number isn't a palindrome."); 17 | 18 | -------------------------------------------------------------------------------- /Java Programs/PowerCalculate.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class PowerCalculate { 4 | public static void main(String[] args) { 5 | System.out.println(pow(3, 3)); 6 | } 7 | 8 | // x raise to power y/ 9 | static int pow(int x, int y){ 10 | if(y == 0) return 1; 11 | return x * pow(x, y-1); 12 | } 13 | // (2, 3) 14 | // 2 * (2, 2) 15 | // ``````--> 2 * (2, 1) 16 | // ````````````````--> 2 * 1 17 | } 18 | -------------------------------------------------------------------------------- /Java Programs/PowerSet.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class PowerSet { 7 | public static void main(String[] args) { 8 | int[] arr = {3,4,5}; 9 | char[] chrs = {'a', 'b', 'c', 'd'}; 10 | getPowerSet(chrs, new ArrayList<>(), 0); 11 | } 12 | 13 | static void getPowerSet(char[] arr, List localList, int idx){ 14 | if (idx >= arr.length){ 15 | if (localList.size() == 2) System.out.println(localList); 16 | return; 17 | } 18 | localList.add(arr[idx]); 19 | getPowerSet(arr, localList, idx+1); 20 | localList.remove(localList.size()-1); 21 | getPowerSet(arr, localList, idx+1); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Java Programs/PrintNnumber.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class PrintNnumber { 4 | public static void main(String[] args) { 5 | fun(5); 6 | } 7 | static void fun(int n){ 8 | if (n==0) return; 9 | fun(n-1); 10 | System.out.print(n + " "); 11 | } 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Java Programs/README.md: -------------------------------------------------------------------------------- 1 | # Upload any of your interesting Java Programs here. 2 | ### Please avoid Spam and Invalid submissions 3 | -------------------------------------------------------------------------------- /Java Programs/RainWaterTrapping.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class RainWaterTrapping { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | System.out.println("Enter length of array:"); 7 | int len = sc.nextInt(); 8 | 9 | int[] bars = new int[len]; 10 | for (int i = 0; i < bars.length; i++) { 11 | bars[i] = sc.nextInt(); 12 | } 13 | sc.close(); 14 | 15 | int quantity = trap(bars); 16 | System.out.println(quantity); 17 | } 18 | 19 | private static int trap(int[] arr) { 20 | int left = 0, right = arr.length - 1; // 'left' pointer points to first index initially and 'right' pointer 21 | // points to the last element in the array initially 22 | 23 | int maxLeft = 0, maxRight = 0, ans = 0;// maxLeft stores height of longest bar on the left of a certain bar 24 | // maxRight stores the height of longest bar on the right of a certain 25 | // bar 26 | while (left < right) { // run the loop as long as left pointer doesn't cross right pointer 27 | 28 | if (arr[left] < arr[right]) { // if arr[left] < arr[right], update maxLeft and ans and increment the left 29 | // pointer 30 | maxLeft = Math.max(maxLeft, arr[left]); 31 | ans += maxLeft - arr[left]; 32 | left++; 33 | } 34 | 35 | else { // else, perform the same steps but in this case, decrement right pointer 36 | maxRight = Math.max(maxRight, arr[right]); 37 | ans += maxRight - arr[right]; 38 | right--; 39 | } 40 | } 41 | 42 | return ans; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Java Programs/ReverseRecursion: -------------------------------------------------------------------------------- 1 | public class Reverse { 2 | 3 | public static void main(String[] args) { 4 | String sentence = "Go work"; 5 | String reversed = reverse(sentence); 6 | System.out.println("The reversed sentence is: " + reversed); 7 | } 8 | 9 | public static String reverse(String sentence) { 10 | if (sentence.isEmpty()) 11 | return sentence; 12 | 13 | return reverse(sentence.substring(1)) + sentence.charAt(0); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Java Programs/SecondLargest.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | class SecondLargest 5 | { 6 | public static void main(String args[]) 7 | { 8 | int a,b,c; 9 | int second=0; 10 | a = 100; b = 20; c = 30; 11 | if(a>b && a>c) 12 | { 13 | if (b>c) 14 | { 15 | second = b; 16 | } 17 | if (c>b) 18 | { 19 | second = c; 20 | } 21 | } 22 | else if(b>a && b>c) 23 | { 24 | if (a>c) 25 | { 26 | second = a; 27 | } 28 | if (c>a) 29 | { 30 | second = c; 31 | } 32 | } 33 | else 34 | { 35 | if (b>a) 36 | { 37 | second = b; 38 | } 39 | if (a>b) 40 | { 41 | second = a; 42 | } 43 | } 44 | System.out.println("Second Largest is "+second); 45 | 46 | } 47 | 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Java Programs/SecondLargestElement.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class SecondLargestElement { 4 | public static void main(String[] args) { 5 | int[] arr = {1,2,5,3,0,1,2,4}; 6 | int large = Integer.MIN_VALUE; 7 | int sLarge = Integer.MIN_VALUE; 8 | for (int i = 0; i < arr.length; i++) { 9 | if (arr[i] > large){ 10 | sLarge = large; 11 | large = arr[i]; 12 | } else if (arr[i] > sLarge && arr[i] < large){ 13 | sLarge = arr[i]; 14 | } 15 | } 16 | System.out.println(sLarge); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java Programs/SlidingWindow.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | //Given an array of integers of size ‘n’. 4 | // Our aim is to calculate the maximum sum of ‘k’ consecutive elements in the array. 5 | // 6 | // Input : arr[] = {100, 200, 300, 400} 7 | // k = 2 8 | // Output : 700 9 | // 10 | // Input : arr[] = {1, 4, 2, 10, 23, 3, 1, 0, 20} 11 | // k = 4 12 | // Output : 39 13 | // We get maximum sum by adding subarray {4, 2, 10, 23} 14 | // of size 4. 15 | // 16 | // Input : arr[] = {2, 3} 17 | // k = 3 18 | // Output : -1 19 | // There is no subarray of size 3 as size of whole 20 | // array is 2. 21 | 22 | public class SlidingWindow { 23 | public static void main(String[] args) { 24 | int[] arr = {2, 3}; 25 | int k = 3; 26 | 27 | // output: 39 28 | int ans = maxSum(arr, k); 29 | System.out.println(ans); 30 | } 31 | 32 | 33 | 34 | static int maxSum(int[] arr, int k) { 35 | if(k > arr.length){ 36 | return -1; 37 | } 38 | int maxSum = 0; 39 | for (int i = 0; i <= arr.length - k; i++) { 40 | if(sum(arr, i, i+k-1) > maxSum){ 41 | maxSum = sum(arr, i, i+k-1); 42 | } 43 | } 44 | return maxSum; 45 | } 46 | 47 | static int sum(int[] arr, int s, int e){ 48 | int sum = 0; 49 | for (int i=s; i <= e; i++){ 50 | sum += arr[i]; 51 | } 52 | return sum; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Java Programs/SortStrings: -------------------------------------------------------------------------------- 1 | lass Main { 2 | public static void main(String[] args) { 3 | 4 | String[] words = { "Ruby", "C", "Python", "Java" }; 5 | 6 | for(int i = 0; i < 3; ++i) { 7 | for (int j = i + 1; j < 4; ++j) { 8 | 9 | if (words[i].compareTo(words[j]) > 0) { 10 | 11 | String temp = words[i]; 12 | words[i] = words[j]; 13 | words[j] = temp; 14 | } 15 | } 16 | } 17 | 18 | System.out.println("In lexicographical order:"); 19 | 20 | for(int i = 0; i < 4; i++) { 21 | System.out.println(words[i]); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Java Programs/SumOfArray.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class SumOfArray { 4 | public static void main(String[] args) { 5 | int[] arr = {1,5,6,2,9,3}; 6 | System.out.println(sumArray(arr, arr.length)); 7 | } 8 | 9 | static int sumArray(int[] arr, int n) { 10 | if (n==0 || n==1) return arr[0]; 11 | return arr[n-1] + sumArray(arr, n-1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java Programs/SumOfNaturalNumbers.java: -------------------------------------------------------------------------------- 1 | package Recursion; 2 | 3 | public class SumOfNaturalNumbers { 4 | public static void main(String[] args) { 5 | System.out.println(sum(4)); 6 | } 7 | 8 | static int sum(int x){ 9 | if (x < 1) return 0; 10 | if (x == 1) return 1; 11 | return x + sum(x - 1); 12 | } 13 | } -------------------------------------------------------------------------------- /Java Programs/TowerOfHanoi.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class TowerofHanoi 3 | { 4 | public static void main(String args[]) 5 | { 6 | Scanner sc= new Scanner(System.in); 7 | System.out.println("Enter number of discs\n"); 8 | int n= sc.nextInt(); 9 | towerofhanoi(n,'A','C','B'); 10 | } 11 | public static void towerofhanoi(int n,char rod1,char rod2,char rod3) //recursive 12 | { 13 | if(n==1) 14 | { 15 | System.out.println("Move disk 1 from "+ rod1 +" to rod "+rod2+"\n"); 16 | return; 17 | } 18 | towerofhanoi(n-1,rod1,rod3,rod2); 19 | System.out.println("Move disk "+ n + " from rod "+rod1+" to rod "+rod2+"\n"); 20 | towerofhanoi(n-1,rod3,rod2,rod1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Java Programs/TwoPointerAlgo.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | // used to find target sum of two elements 4 | // works only on sorted array 5 | 6 | public class TwoPointerAlgo { 7 | public static void main(String[] args) { 8 | int[] arr = {-4, -1, 0, 2, 3, 4, 7, 9}; 9 | int x = 3; // find two elements that adds to x; 10 | 11 | int i = 0; 12 | int j = arr.length-1; 13 | 14 | while (i x){ 23 | j--; 24 | } else{ 25 | System.out.println(i); 26 | System.out.println(j); 27 | break; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Java Programs/check.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class check 3 | { 4 | public static void main(String a[]) 5 | { 6 | int array[]= {10,15,20,30,50,70,90}; 7 | Scanner sc=new Scanner(System.in); 8 | System.out.print("Enter First Number : "); 9 | int key1= sc.nextInt(); 10 | System.out.print("Enter Second Number : "); 11 | int key2= sc.nextInt(); 12 | int key=key1*key2; 13 | int r=check(array, key); 14 | if(key%2==0) 15 | { 16 | if (r>=0) 17 | { 18 | System.out.println(key+" is Present!"); 19 | } 20 | else 21 | { 22 | System.out.println(key+" is NOT Present!"); 23 | } 24 | } 25 | else 26 | { 27 | System.out.println(key+" is NOT a EVEN Product"); 28 | } 29 | } 30 | public static int check(int a[], int key) 31 | { 32 | for(int i=0;i500) { 12 | System.out.println("Count of ₹500 :"+(int)(cur/500)); 13 | cur = cur%500; 14 | } 15 | if (cur>200) { 16 | System.out.println("Count of ₹200 :"+(int)(cur/200)); 17 | cur = cur%200; 18 | } 19 | if (cur>100) { 20 | System.out.println("Count of ₹100 :"+(int)(cur/100)); 21 | cur = cur%100; 22 | } 23 | if (cur>50) { 24 | System.out.println("Count of ₹50 :"+(int)(cur/50)); 25 | cur = cur%50; 26 | } 27 | if (cur>10) { 28 | System.out.println("Count of ₹10 :"+(int)(cur/10)); 29 | cur = cur%10; 30 | } 31 | if (cur>5) { 32 | System.out.println("Count of ₹5 :"+(int)(cur/5)); 33 | cur = cur%5; 34 | } 35 | if (cur>2) { 36 | System.out.println("Count of ₹2 :"+(int)(cur/2)); 37 | cur = cur%2; 38 | } 39 | if (cur>1) { 40 | System.out.println("Count of ₹1 :"+(int)(cur/1)); 41 | cur = cur%1; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Java Programs/odd.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class odd 4 | { 5 | public static void main(String args[]) 6 | { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.print("Enter the Number : "); 9 | int number = sc.nextInt(); 10 | System.out.print("List of odd numbers from 1 to "+number+": \n"); 11 | for (int i=1; i<=number; i++) 12 | { 13 | if (i%2!=0) 14 | { 15 | System.out.println(i + " "); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java Programs/rec.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | class rec 5 | { 6 | public static void main(String args[]) 7 | { 8 | int a,b,c; 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the length of the Rectange : "); 11 | a = sc.nextInt(); 12 | System.out.println("Enter the height of the Rectange : "); 13 | b = sc.nextInt(); 14 | System.out.println("The Area of the Rectange = "+(a*b)+"\n"+"The Perimeter of the Rectange = "+(2*(a+b))); 15 | } 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Java Programs/small_large.java: -------------------------------------------------------------------------------- 1 | public class small_large 2 | { 3 | public static void main(String args[]) 4 | { 5 | int a[]= {4,23,6,20,94,22,100}; 6 | int i,small=a[0],large=a[0]; 7 | for (i=0;ia[i]) 14 | { 15 | small=a[i]; 16 | } 17 | } 18 | System.out.println("Smallest : "+small); 19 | System.out.println("Largest : "+large); 20 | } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /Java Programs/sumnavg.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | class sumnavg 5 | { 6 | public static void main(String args[]) 7 | { 8 | int a,b,c,sum,average; 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the First Number : "); 11 | a = sc.nextInt(); 12 | System.out.println("Enter the Second Number : "); 13 | b = sc.nextInt(); 14 | System.out.println("Enter the Third Number : "); 15 | c = sc.nextInt(); 16 | System.out.println("Sum of 3 Numbers : "+(a+b+c)+"\n"+"Average of 3 Numbers : "+((a+b+c)/3)); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Java Programs/validSquare: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/valid-perfect-square/ 2 | public class validSquare { 3 | public static void main(String[] args) { 4 | int num = 808201; 5 | boolean ans = isPerfectSquare(num); 6 | System.out.println(ans); 7 | } 8 | 9 | private static boolean isPerfectSquare(int num) { 10 | long start = 1L; 11 | long end; 12 | long lNum = (long) num; 13 | if (lNum < 16 && lNum >= 4){ 14 | end = lNum/2; 15 | }else if (lNum >= 16) { 16 | end = lNum/4; 17 | }else { 18 | end = lNum; 19 | } 20 | if( start*start == lNum || end*end == lNum){ 21 | return true; 22 | } 23 | while (start < end){ 24 | Long mid = start + (end - start)/2; 25 | if( start*start == lNum || end*end == lNum){ 26 | return true; 27 | } 28 | if(mid*mid == lNum){ 29 | return true; 30 | }else if(mid*mid > lNum){ 31 | end = mid - 1; 32 | }else if(mid*mid < lNum){ 33 | start = mid + 1; 34 | } 35 | } 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Java Programs/value2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class value2 3 | { 4 | public static void main(String a[]) 5 | { 6 | Scanner sc=new Scanner(System.in); 7 | System.out.print("Enter the Number : "); 8 | int f= sc.nextInt(); 9 | if(f>2) 10 | { 11 | System.out.print("Enter the Number of time to devide: "); 12 | int s= sc.nextInt(); 13 | int r = s*2; 14 | //System.out.println(f%r!=0); 15 | } 16 | else 17 | { 18 | System.out.println("The Number is less than 2"); 19 | } 20 | 21 | 22 | 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Java Script Programs/BMIcalculator.js: -------------------------------------------------------------------------------- 1 | let BMIcalculation = (weight, height) => { 2 | let BMI = weight / (height * height); 3 | if (BMI < 18.5) { 4 | console.log("You are underweight"); 5 | } else if (BMI >= 18.5 && BMI < 25) { 6 | console.log("Your weight is in a healthy range"); 7 | } else if (BMI >= 25 && BMI < 30) { 8 | console.log("You are overweight"); 9 | } else if (BMI >= 30) { 10 | console.log("You are obese"); 11 | } else { 12 | console.log("Please enter weight and height"); 13 | } 14 | }; 15 | 16 | BMIcalculation(80, 1.65); 17 | BMIcalculation(70, 1.86); 18 | BMIcalculation(55, 1.9); 19 | -------------------------------------------------------------------------------- /Java Script Programs/Readme.md: -------------------------------------------------------------------------------- 1 | # Upload any of your interesting Java Script Programs here. 2 | ### Please avoid Spam and Invalid submissions 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Rizwan Nizarudin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Python Programs/Armstrong.py: -------------------------------------------------------------------------------- 1 | # Python program to determine whether 2 | # the number is Armstrong number or not 3 | 4 | # Function to calculate x raised to 5 | # the power y 6 | def power(x, y): 7 | 8 | if y == 0: 9 | return 1 10 | if y % 2 == 0: 11 | return power(x, y // 2) * power(x, y // 2) 12 | 13 | return x * power(x, y // 2) * power(x, y // 2) 14 | 15 | # Function to calculate order of the number 16 | def order(x): 17 | 18 | # Variable to store of the number 19 | n = 0 20 | while (x != 0): 21 | n = n + 1 22 | x = x // 10 23 | 24 | return n 25 | 26 | # Function to check whether the given 27 | # number is Armstrong number or not 28 | def isArmstrong(x): 29 | 30 | n = order(x) 31 | temp = x 32 | sum1 = 0 33 | 34 | while (temp != 0): 35 | r = temp % 10 36 | sum1 = sum1 + power(r, n) 37 | temp = temp // 10 38 | 39 | # If condition satisfies 40 | return (sum1 == x) 41 | 42 | # Driver code 43 | x = 153 44 | print(isArmstrong(x)) 45 | 46 | x = 1253 47 | print(isArmstrong(x)) 48 | -------------------------------------------------------------------------------- /Python Programs/Automated_Text_on_Image_Using_PIL.py: -------------------------------------------------------------------------------- 1 | from PIL import Image, ImageFont, ImageDraw 2 | test_image = Image.open("sbik copy.png") 3 | W,H=(4320,4320) 4 | my_font = ImageFont.truetype("Quadrats.ttf", 850) 5 | i = 0 6 | while i!=10001: 7 | text3=str(i) 8 | im = Image.new("RGBA", (W, H), "black") 9 | draw = ImageDraw.Draw(im) 10 | #image_edit.text((2160, 2160), text3, (237, 230, 211),font=my_font, align="left") 11 | w, h = draw.textsize(text3) 12 | draw.text((W / 2, H / 2), text3, fill="white", font=my_font, anchor="mm") 13 | im.save("Sbik_images/"+str(i)+".png") 14 | i=i+1 15 | -------------------------------------------------------------------------------- /Python Programs/Bubblesort.py: -------------------------------------------------------------------------------- 1 | a = [] 2 | number = int(input("Please Enter the Total Number of Elements : ")) 3 | for i in range(number): 4 | value = int(input("Please enter the %d Element of List1 : " %i)) 5 | a.append(value) 6 | 7 | for i in range(number -1): 8 | for j in range(number - i - 1): 9 | if(a[j] > a[j + 1]): 10 | temp = a[j] 11 | a[j] = a[j + 1] 12 | a[j + 1] = temp 13 | 14 | print("The Sorted List in Ascending Order : ", a) 15 | print("\nElectricity Bill = %.2f" %total) 16 | -------------------------------------------------------------------------------- /Python Programs/Counting_Objects_in_image.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import cvlib as cv 5 | from cvlib.object_detection import draw_bbox 6 | from numpy.lib.polynomial import poly 7 | 8 | 9 | img = cv2.imread('image1.jpg') 10 | img1 = cv2.cvtColor(img,cv2.COLOR_BGR2RGB) 11 | plt.figure(figsize=(10,10)) 12 | plt.axis('off') 13 | plt.imshow(img1) 14 | plt.show() 15 | 16 | 17 | box, label, count = cv.detect_common_objects(img) 18 | output = draw_bbox(img, box, label, count) 19 | 20 | 21 | output = cv2.cvtColor(output,cv2.COLOR_BGR2RGB) 22 | plt.figure(figsize=(10,10)) 23 | plt.axis('off') 24 | plt.imshow(output) 25 | plt.show() 26 | 27 | 28 | print("Number of objects in this image are " +str(len(label))) 29 | -------------------------------------------------------------------------------- /Python Programs/Drawing-Car-Using-Python.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | car_scr = turtle 3 | car_scr.color('black') 4 | car_scr.Screen().bgcolor("#ABEBC6") 5 | 6 | def Draw_Car(i,j): 7 | # Drawing the Upper Body 8 | car_scr.fillcolor("#2980B9") 9 | car_scr.penup() 10 | car_scr.goto(i,j) 11 | car_scr.pendown() 12 | car_scr.begin_fill() 13 | car_scr.forward(370) 14 | car_scr.left(90) 15 | car_scr.forward(50) 16 | car_scr.left(90) 17 | car_scr.forward(370) 18 | car_scr.left(90) 19 | car_scr.forward(50) 20 | car_scr.end_fill() 21 | 22 | #Draw the Windows 23 | car_scr.fillcolor("#D5DBDB") 24 | car_scr.penup() 25 | car_scr.goto(i+100, 50) 26 | car_scr.pendown() 27 | car_scr.begin_fill() 28 | car_scr.setheading(45) 29 | car_scr.forward(70) 30 | car_scr.setheading(0) 31 | car_scr.forward(100) 32 | car_scr.setheading(-45) 33 | car_scr.forward(70) 34 | car_scr.setheading(90) 35 | car_scr.end_fill() 36 | car_scr.penup() 37 | car_scr.goto(i+200, 50) 38 | car_scr.pendown() 39 | car_scr.forward(49.50) 40 | 41 | # Draw the two wheels 42 | car_scr.penup() 43 | car_scr.goto(i+100, -10-j) 44 | car_scr.pendown() 45 | car_scr.color('black') 46 | car_scr.fillcolor('black') 47 | car_scr.begin_fill() 48 | car_scr.circle(20) 49 | car_scr.end_fill() 50 | car_scr.penup() 51 | car_scr.goto(i+300, -10-j) 52 | car_scr.pendown() 53 | car_scr.color('black') 54 | car_scr.fillcolor('black') 55 | car_scr.begin_fill() 56 | car_scr.circle(20) 57 | car_scr.end_fill() 58 | 59 | Draw_Car(-200,0) 60 | 61 | car_scr.done() 62 | -------------------------------------------------------------------------------- /Python Programs/Electricitybill.py: -------------------------------------------------------------------------------- 1 | units = int(input(" Please enter Number of Units you Consumed : ")) 2 | 3 | if(units < 50): 4 | amount = units * 2.60 5 | surcharge = 25 6 | elif(units <= 100): 7 | amount = 130 + ((units - 50) * 3.25) 8 | surcharge = 35 9 | elif(units <= 200): 10 | amount = 130 + 162.50 + ((units - 100) * 5.26) 11 | surcharge = 45 12 | else: 13 | amount = 130 + 162.50 + 526 + ((units - 200) * 8.45) 14 | surcharge = 75 15 | 16 | total = amount + surcharge 17 | print("\nElectricity Bill = %.2f" %total) 18 | -------------------------------------------------------------------------------- /Python Programs/Fahrenheit_to_Celsius.py: -------------------------------------------------------------------------------- 1 | temp = input("Input the temperature you want to convert: ") 2 | degree = int(temp[:-1]) 3 | i_convention = temp[-1] 4 | 5 | if i_convention.upper() == "C": 6 | result = int(round((9 * degree) / 5 + 32)) 7 | o_convention = "Fahrenheit" 8 | elif i_convention.upper() == "F": 9 | result = int(round((degree - 32) * 5 / 9)) 10 | o_convention = "Celsius" 11 | else: 12 | print("Input proper convention:") 13 | quit() 14 | print("The temperature in", o_convention, "is", result, "degrees.") 15 | -------------------------------------------------------------------------------- /Python Programs/Generate-QR-Code.py: -------------------------------------------------------------------------------- 1 | # Importing pyqrcode library 2 | import pyqrcode 3 | 4 | # Set QR code website url 5 | website = "https://durgesh716.github.io/Portfolio-Website/" 6 | 7 | # Generate qr code 8 | url = pyqrcode.create(website) 9 | 10 | # Save QR code 11 | url.svg("DurgeshQR.svg", scale=8) 12 | -------------------------------------------------------------------------------- /Python Programs/Image-to-sketch.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import matplotlib.pyplot as plt 3 | plt.style.use('seaborn') 4 | 5 | img = cv2.imread("image1.png") 6 | img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB) 7 | plt.figure(figsize=(8,8)) 8 | plt.imshow(img) 9 | plt.axis("off") 10 | plt.title("Original Image") 11 | plt.show() 12 | 13 | img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 14 | plt.figure(figsize=(8,8)) 15 | plt.imshow(img_gray,cmap="gray") 16 | plt.axis("off") 17 | plt.title("GrayScale Image") 18 | plt.show() 19 | 20 | img_invert = cv2.bitwise_not(img_gray) 21 | plt.figure(figsize=(8,8)) 22 | plt.imshow(img_invert,cmap="gray") 23 | plt.axis("off") 24 | plt.title("Inverted Image") 25 | plt.show() 26 | 27 | img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0) 28 | plt.figure(figsize=(8,8)) 29 | plt.imshow(img_smoothing,cmap="gray") 30 | plt.axis("off") 31 | plt.title("Smoothen Image") 32 | plt.show() 33 | 34 | final = cv2.divide(img_gray, 255 - img_smoothing, scale=255) 35 | plt.figure(figsize=(8,8)) 36 | plt.imshow(final,cmap="gray") 37 | plt.axis("off") 38 | plt.title("Final Sketch Image") 39 | plt.show() 40 | -------------------------------------------------------------------------------- /Python Programs/IndianFlag.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | def rectangle(color): 3 | t.begin_fill() 4 | t.fillcolor(color) 5 | for i in range(2): 6 | t.forward(400) 7 | t.right(90) 8 | t.forward(100) 9 | t.right(90) 10 | t.end_fill() 11 | 12 | t=turtle.Turtle() 13 | turtle.screensize(1100,1100) 14 | turtle.title("National Flag Of India ") 15 | t.up() 16 | t.pensize(4) 17 | t.goto(0,-300) 18 | t.down() 19 | t.goto(0,400) 20 | rectangle("orange") 21 | t.goto(0,300) 22 | t.forward(200) 23 | t.color("blue") 24 | t.circle(-50) 25 | t.setheading(270) 26 | t.forward(50) 27 | t.setheading(0) 28 | for i in range(24): 29 | t.forward(45) 30 | t.bk(45) 31 | t.left(15) 32 | t.setheading(90) 33 | t.forward(50) 34 | t.setheading(0) 35 | t.color("black") 36 | t.forward(200) 37 | t.right(90) 38 | t.forward(100) 39 | t.right(90) 40 | t.forward(400) 41 | t.right(90) 42 | t.forward(100) 43 | t.right(90) 44 | t.goto(0,200) 45 | rectangle("green") 46 | -------------------------------------------------------------------------------- /Python Programs/LongestPalindromicSubstring.py: -------------------------------------------------------------------------------- 1 | def longestPalindrome(self, s): 2 | n = len(s) 3 | dp = [[False for i in range(n)] for j in range(n)] 4 | ans = '' 5 | maxlen = 0 6 | 7 | #Strings of length 1 8 | for i in range(n): 9 | dp[i][i] = True 10 | ans = s[i] 11 | maxlen = 1 12 | 13 | #Strings of length 2 14 | for i in range(n-1): 15 | if s[i] == s[i+1]: 16 | maxlen = 2 17 | ans = s[i:i+2] 18 | dp[i][i+1] = True 19 | 20 | #Strings of length > 2 21 | for j in range(n): 22 | for i in range(j-1): 23 | if s[i]==s[j] and dp[i+1][j-1] is True: 24 | dp[i][j] = True 25 | if maxlen < j-i+1: 26 | maxlen = max(maxlen, j-i+1) 27 | ans = s[i:j+1] 28 | 29 | 30 | return ans 31 | -------------------------------------------------------------------------------- /Python Programs/Minimum Elements to Add to Form a Given Sum.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def minElements(self, nums, limit, goal): 3 | d=abs(goal-sum(nums)) 4 | c=d%limit 5 | if c==0: 6 | return d//limit 7 | else: 8 | return d//limit+1 9 | 10 | """ 11 | :type nums: List[int] 12 | :type limit: int 13 | :type goal: int 14 | :rtype: int 15 | """ 16 | 17 | -------------------------------------------------------------------------------- /Python Programs/README.md: -------------------------------------------------------------------------------- 1 | # Upload any of your interesting Python Programs here. 2 | ### Please avoid Spam and Invalid submissions 3 | -------------------------------------------------------------------------------- /Python Programs/Unimodal.py: -------------------------------------------------------------------------------- 1 | #https://codeforces.com/contest/831/problem/A 2 | n = int(input()) 3 | l = list( map(int,input().split())) 4 | j = 0 5 | i = 0 6 | a = max(l) 7 | max_index = l.index(max(l)) 8 | for i in range(0,n-1): 9 | if l[i] < l[i+1] : 10 | j = j+1 11 | else : 12 | break 13 | for i in range(i,n-1) : 14 | if l[i] == l[i+1] : 15 | j = j+1 16 | else : 17 | break 18 | for i in range(i,n-1) : 19 | if l[i] > l[i+1] : 20 | j = j+1 21 | else : 22 | break 23 | if j == n-1 : 24 | print("YES") 25 | else : 26 | print("NO") 27 | -------------------------------------------------------------------------------- /Python Programs/binary_search.py: -------------------------------------------------------------------------------- 1 | def binary_search(arr, low, high, x): 2 | if high >= low: 3 | mid = (high + low) // 2 4 | if arr[mid] == x: 5 | return mid 6 | elif arr[mid] > x: 7 | return binary_search(arr, low, mid - 1, x) 8 | else: 9 | return binary_search(arr, mid + 1, high, x) 10 | 11 | else: 12 | return -1 13 | 14 | arr = [ 2, 3, 4, 10, 40 ] 15 | x = 10 16 | result = binary_search(arr, 0, len(arr)-1, x) 17 | 18 | if result != -1: 19 | print("Element is present at index", str(result)) 20 | else: 21 | print("Element is not present in array") 22 | -------------------------------------------------------------------------------- /Python Programs/binary_tree_inorder_traversal. py: -------------------------------------------------------------------------------- 1 | # Python3 program to for tree traversals 2 | 3 | # A class that represents an individual node in a 4 | # Binary Tree 5 | 6 | 7 | class Node: 8 | def __init__(self, key): 9 | self.left = None 10 | self.right = None 11 | self.val = key 12 | 13 | 14 | # A function to do inorder tree traversal 15 | def printInorder(root): 16 | 17 | if root: 18 | 19 | # First recur on left child 20 | printInorder(root.left) 21 | 22 | # then print the data of node 23 | print(root.val), 24 | 25 | # now recur on right child 26 | printInorder(root.right) 27 | 28 | 29 | # Driver code 30 | if __name__ == "__main__": 31 | root = Node(1) 32 | root.left = Node(2) 33 | root.right = Node(3) 34 | root.left.left = Node(4) 35 | root.left.right = Node(5) 36 | 37 | # Function call 38 | print "\nInorder traversal of binary tree is" 39 | printInorder(root) 40 | -------------------------------------------------------------------------------- /Python Programs/binary_tree_preorder_traversal. py: -------------------------------------------------------------------------------- 1 | # Python3 program to for tree traversals 2 | 3 | # A class that represents an individual node in a 4 | # Binary Tree 5 | 6 | 7 | class Node: 8 | def __init__(self, key): 9 | self.left = None 10 | self.right = None 11 | self.val = key 12 | 13 | 14 | # A function to do preorder tree traversal 15 | def printPreorder(root): 16 | 17 | if root: 18 | 19 | # First print the data of node 20 | print(root.val), 21 | 22 | # Then recur on left child 23 | printPreorder(root.left) 24 | 25 | # Finally recur on right child 26 | printPreorder(root.right) 27 | 28 | 29 | # Driver code 30 | if __name__ == "__main__": 31 | root = Node(1) 32 | root.left = Node(2) 33 | root.right = Node(3) 34 | root.left.left = Node(4) 35 | root.left.right = Node(5) 36 | 37 | # Function call 38 | print "Preorder traversal of binary tree is" 39 | printPreorder(root) 40 | -------------------------------------------------------------------------------- /Python Programs/binarysearch.py: -------------------------------------------------------------------------------- 1 | def BinarySearch(lys, val): 2 | first = 0 3 | last = len(lys)-1 4 | index = -1 5 | while (first <= last) and (index == -1): 6 | mid = (first+last)//2 7 | if lys[mid] == val: 8 | index = mid 9 | else: 10 | if val List[int]: 3 | # Initialize binary search bounds 4 | left = 0 5 | right = len(arr) - k 6 | 7 | # Binary search against the criteria described 8 | while left < right: 9 | mid = (left + right) // 2 10 | if x - arr[mid] > arr[mid + k] - x: 11 | left = mid + 1 12 | else: 13 | right = mid 14 | 15 | return arr[left:left + k] 16 | -------------------------------------------------------------------------------- /Python Programs/calc.py: -------------------------------------------------------------------------------- 1 | def add(x, y): 2 | return x + y 3 | 4 | def subtract(x, y): 5 | return x - y 6 | 7 | def multiply(x, y): 8 | return x * y 9 | 10 | def divide(x, y): 11 | return x / y 12 | 13 | print("Select operation.") 14 | print("1.Add") 15 | print("2.Subtract") 16 | print("3.Multiply") 17 | print("4.Divide") 18 | 19 | while True: 20 | choice = input("Enter choice(1/2/3/4): ") 21 | 22 | if choice in ('1', '2', '3', '4'): 23 | num1 = float(input("Enter first number: ")) 24 | num2 = float(input("Enter second number: ")) 25 | 26 | if choice == '1': 27 | print(num1, "+", num2, "=", add(num1, num2)) 28 | 29 | elif choice == '2': 30 | print(num1, "-", num2, "=", subtract(num1, num2)) 31 | 32 | elif choice == '3': 33 | print(num1, "*", num2, "=", multiply(num1, num2)) 34 | 35 | elif choice == '4': 36 | print(num1, "/", num2, "=", divide(num1, num2)) 37 | 38 | next_calculation = input("Let's do next calculation? (yes/no): ") 39 | if next_calculation == "no": 40 | break 41 | 42 | else: 43 | print("Invalid Input") 44 | -------------------------------------------------------------------------------- /Python Programs/calendar.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import calendar 3 | 4 | cal = calendar.month(2008, 1) 5 | print "Here is the calendar:" 6 | print cal 7 | -------------------------------------------------------------------------------- /Python Programs/count-negatives-in-matrix.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def countNegatives(self, grid): 3 | """ 4 | :type grid: List[List[int]] 5 | :rtype: int 6 | """ 7 | count = 0 8 | for i in grid: 9 | for j in i: 10 | if j < 0: 11 | count += 1 12 | return count 13 | -------------------------------------------------------------------------------- /Python Programs/db_access.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import MySQLdb 4 | 5 | # Open database connection 6 | db = MySQLdb.connect("localhost","testuser","test123","TESTDB" ) 7 | 8 | # prepare a cursor object using cursor() method 9 | cursor = db.cursor() 10 | 11 | sql = "SELECT * FROM EMPLOYEE \ 12 | WHERE INCOME > '%d'" % (1000) 13 | try: 14 | # Execute the SQL command 15 | cursor.execute(sql) 16 | # Fetch all the rows in a list of lists. 17 | results = cursor.fetchall() 18 | for row in results: 19 | fname = row[0] 20 | lname = row[1] 21 | age = row[2] 22 | sex = row[3] 23 | income = row[4] 24 | # Now print fetched result 25 | print "fname=%s,lname=%s,age=%d,sex=%s,income=%d" % \ 26 | (fname, lname, age, sex, income ) 27 | except: 28 | print "Error: unable to fecth data" 29 | 30 | # disconnect from server 31 | db.close() 32 | -------------------------------------------------------------------------------- /Python Programs/electric.py: -------------------------------------------------------------------------------- 1 | units = int(input(" Please enter Number of Units you Consumed : ")) 2 | 3 | if(units < 50): 4 | amount = units * 2.60 5 | surcharge = 25 6 | elif(units <= 100): 7 | amount = 130 + ((units - 50) * 3.25) 8 | surcharge = 35 9 | elif(units <= 200): 10 | amount = 130 + 162.50 + ((units - 100) * 5.26) 11 | surcharge = 45 12 | else: 13 | amount = 130 + 162.50 + 526 + ((units - 200) * 8.45) 14 | surcharge = 75 15 | 16 | total = amount + surcharge 17 | print("\nElectricity Bill = %.2f" %total) 18 | -------------------------------------------------------------------------------- /Python Programs/first.py: -------------------------------------------------------------------------------- 1 | def fibonacci(): 2 | nterms = int(input("How many terms? ")) 3 | n1, n2 = 0, 1 4 | count = 0 5 | if nterms <= 0: 6 | print("Please enter a positive integer") 7 | elif nterms == 1: 8 | print("Fibonacci sequence upto", nterms, ":") 9 | print(n1) 10 | else: 11 | print("Fibonacci sequence:") 12 | while count < nterms: 13 | print(n1) 14 | nth = n1 + n2 15 | n1 = n2 16 | n2 = nth 17 | count += 1 18 | fibonacci() -------------------------------------------------------------------------------- /Python Programs/fourth.py: -------------------------------------------------------------------------------- 1 | def palindrome(): 2 | n = int(input("Enter number: ")) 3 | temp = n 4 | rev = 0 5 | while (n > 0): 6 | dig = n % 10 7 | rev = rev * 10 + dig 8 | n = n // 10 9 | if (temp == rev): 10 | print("The number is a palindrome!") 11 | else: 12 | print("The number is not a palindrome!") 13 | palindrome() -------------------------------------------------------------------------------- /Python Programs/longestValidParentheses.py: -------------------------------------------------------------------------------- 1 | //Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. 2 | 3 | //https://leetcode.com/problems/longest-valid-parentheses/ 4 | 5 | class Solution: 6 | def longestValidParentheses(self, s: str) -> int: 7 | queue = collections.deque() 8 | queue.append(0) 9 | longest = 0 10 | for p in s: 11 | if p == '(': 12 | queue.append(0) 13 | if p == ')': 14 | if len(queue) > 1: 15 | length = queue.pop() + 2 16 | queue[-1] += length 17 | longest = max(longest, queue[-1]) 18 | else: 19 | queue[-1] = 0 20 | return longest 21 | -------------------------------------------------------------------------------- /Python Programs/multilevelInheritance.py: -------------------------------------------------------------------------------- 1 | class Student: 2 | roll_number = 0 3 | 4 | @classmethod 5 | def setRollNumber(cls,r): 6 | cls.roll_number = r; 7 | 8 | 9 | class Exam(Student): 10 | mathsMarks = 0.0 11 | physicsMarks = 0.0 12 | 13 | @classmethod 14 | def setMarks(cls,marksmaths,marksPhysics): 15 | cls.mathsMarks = marksmaths 16 | cls.physicsMarks = marksPhysics 17 | 18 | 19 | class Result(Exam): 20 | def displayResult(self): 21 | print(f"The Roll Number of the Student is {self.roll_number}.\nThe marks obtained in maths are {self.mathsMarks}.\nThe marks obtained in physics are {self.physicsMarks}.\nYour Result is {(self.mathsMarks+self.physicsMarks)/2}%.") 22 | 23 | 24 | 25 | yogesh = Result() 26 | yogesh.setRollNumber(420) 27 | yogesh.setMarks(94.0,90.0) 28 | yogesh.displayResult(); 29 | 30 | 31 | -------------------------------------------------------------------------------- /Python Programs/number_guessing_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | import math 3 | # Taking Inputs 4 | lower = int(input("Enter Lower bound:- ")) 5 | 6 | # Taking Inputs 7 | upper = int(input("Enter Upper bound:- ")) 8 | 9 | # generating random number between the lower and upper 10 | 11 | x = random.randint(lower, upper) 12 | #The math.log() method returns the natural logarithm of a number, or the logarithm of number to base. 13 | 14 | print("\n\tYou've only ", 15 | round(math.log(upper - lower + 1, 2)), #The round() function returns a floating point number that is a 16 | " chances to guess the integer!\n") #rounded version of the specified number, with the specified number of decimals. 17 | 18 | 19 | # Initializing the number of guesses. 20 | count = 0 21 | 22 | # for calculation of minimum number of 23 | # guesses depends upon range 24 | while count < math.log(upper - lower + 1, 2): 25 | count += 1 26 | 27 | # taking guessing number as input 28 | guess = int(input("Guess a number:- ")) 29 | 30 | # Condition testing 31 | if x == guess: 32 | print("Congratulations you did it in ", 33 | count, " try") 34 | # Once guessed, loop will break 35 | break 36 | elif x > guess: 37 | print("You guessed too small!") 38 | elif x < guess: 39 | print("You Guessed too high!") 40 | 41 | # If Guessing is more than required guesses, 42 | # shows this output. 43 | if count >= math.log(upper - lower + 1, 2): 44 | print("\nThe number is %d" % x) 45 | print("\tBetter Luck Next time!") 46 | 47 | # Better to use This source Code on pycharm! -------------------------------------------------------------------------------- /Python Programs/palindrome.py: -------------------------------------------------------------------------------- 1 | def palindrome_check(a): 2 | if a.lower() == a.lower()[::-1]: 3 | print("Palindrome Confirmed") 4 | else: 5 | print("Not a Palindrome") 6 | 7 | if __name__ == "__main__": 8 | a = input("Enter first string: ") 9 | palindrome_check(a) 10 | 11 | -------------------------------------------------------------------------------- /Python Programs/portscanner.py: -------------------------------------------------------------------------------- 1 | 2 | import socket 3 | import time 4 | 5 | portlist = { 6 | "20" : "ftp data transfer", 7 | "21" : "ftp command control", 8 | "22" : "ssh", 9 | "23" : "telnet", 10 | "25" : "smpt", 11 | "53" : "dns", 12 | "80" : "http", 13 | "110" : "pop3", 14 | "111" : "rpcbind", 15 | "119" : "nntp", 16 | "123" : "ntp", 17 | "135" : "msrpc", 18 | "139" : "netbios-ssn", 19 | "143" : "imap", 20 | "161" : "snmp", 21 | "194" : "irc", 22 | "443" : "https", 23 | "445" : "microsoft-ds", 24 | "993" : "imaps", 25 | "1723" : "pptp", 26 | "3306" : "mysql", 27 | "5900" : "vnc", 28 | "8080" : "http-proxy" 29 | } 30 | 31 | def check_port(ip, port): 32 | try: 33 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 34 | rslt = sock.connect_ex((ip, int(port))) 35 | sock.close() 36 | return rslt 37 | except: 38 | return 1 39 | 40 | def scan(ip): 41 | open_ports = [] 42 | for port in portlist: 43 | if check_port(ip, port) == 0: 44 | open_ports.append(port) 45 | return open_ports 46 | 47 | def main(): 48 | open_ports = [] 49 | ip = str(input("Please enter the scanned IP address: ")) 50 | start_time = time.time() 51 | open_ports = scan(ip) 52 | dur = round((time.time() - start_time), 2) 53 | num = len(open_ports) 54 | print(f"""\n 55 | Scan Results for {ip} 56 | {num} ports are open. 57 | Scan lasted {dur} seconds. 58 | ------------------------------------\n""") 59 | for port in open_ports: 60 | portval = portlist[port] 61 | print(f"""{port} ---- {portval}\n""") 62 | print("------------------------------------\n") 63 | 64 | if __name__ == "__main__": 65 | main() 66 | -------------------------------------------------------------------------------- /Python Programs/powerOf2.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | A simple programme to check if a number is a power of 2 4 | """ 5 | 6 | 7 | def isPowerofTwo(n): 8 | 9 | return (n != 0) and ((n & (n - 1)) == 0) 10 | 11 | 12 | if __name__ == "__main__": 13 | 14 | # Function call 15 | if isPowerofTwo(30): 16 | print("Yes") 17 | else: 18 | print("No") 19 | 20 | if isPowerofTwo(128): 21 | print("Yes") 22 | else: 23 | print("No") 24 | -------------------------------------------------------------------------------- /Python Programs/printSubArrays.py: -------------------------------------------------------------------------------- 1 | t = int(input()) #number of testcases 2 | for _ in range(t): #loop for testcase 3 | s = int(input()) 4 | arr = input().strip().split() #to split a single line white spaced multiple inputs into arr 5 | for i in range(s): 6 | for j in range(i,s+1): #for grouping 7 | for k in range (i,j): #iterating through a particular group 8 | print(arr[k]+" ",end="") 9 | print() 10 | -------------------------------------------------------------------------------- /Python Programs/quiz_game.py: -------------------------------------------------------------------------------- 1 | # ------------------------- 2 | def new_game(): 3 | 4 | guesses = [] 5 | correct_guesses = 0 6 | question_num = 1 7 | 8 | for key in questions: 9 | print("-------------------------") 10 | print(key) 11 | for i in options[question_num-1]: 12 | print(i) 13 | guess = input("Enter (A, B, C, or D): ") 14 | guess = guess.upper() 15 | guesses.append(guess) 16 | 17 | correct_guesses += check_answer(questions.get(key), guess) 18 | question_num += 1 19 | 20 | display_score(correct_guesses, guesses) 21 | 22 | # ------------------------- 23 | def check_answer(answer, guess): 24 | 25 | if answer == guess: 26 | print("CORRECT!") 27 | return 1 28 | else: 29 | print("WRONG!") 30 | return 0 31 | 32 | # ------------------------- 33 | def display_score(correct_guesses, guesses): 34 | print("-------------------------") 35 | print("RESULTS") 36 | print("-------------------------") 37 | 38 | print("Answers: ", end="") 39 | for i in questions: 40 | print(questions.get(i), end=" ") 41 | print() 42 | 43 | print("Guesses: ", end="") 44 | for i in guesses: 45 | print(i, end=" ") 46 | print() 47 | 48 | score = int((correct_guesses/len(questions))*100) 49 | print("Your score is: "+str(score)+"%") 50 | 51 | # ------------------------- 52 | def play_again(): 53 | 54 | response = input("Do you want to play again? (yes or no): ") 55 | response = response.upper() 56 | 57 | if response == "YES": 58 | return True 59 | else: 60 | return False 61 | # ------------------------- 62 | 63 | 64 | questions = { 65 | "Who created Python?: ": "A", 66 | "What year was Python created?: ": "B", 67 | "Python is tributed to which comedy group?: ": "C", 68 | "Is the Earth round?: ": "A" 69 | } 70 | 71 | options = [["A. Guido van Rossum", "B. Elon Musk", "C. Bill Gates", "D. Mark Zuckerburg"], 72 | ["A. 1989", "B. 1991", "C. 2000", "D. 2016"], 73 | ["A. Lonely Island", "B. Smosh", "C. Monty Python", "D. SNL"], 74 | ["A. True","B. False", "C. sometimes", "D. What's Earth?"]] 75 | 76 | new_game() 77 | 78 | while play_again(): 79 | new_game() 80 | 81 | print("Byeeeeee!") 82 | 83 | -------------------------------------------------------------------------------- /Python Programs/second.py: -------------------------------------------------------------------------------- 1 | list1=eval(input("enter the elements: ")) 2 | L=len(list1) 3 | 4 | for i in range(0,L): 5 | element=list1[i] 6 | s=0 7 | while list1[i]>0: 8 | r=list1[i]%10 9 | list1[i]=list1[i]//10 10 | s=s+r**3 11 | 12 | 13 | 14 | if element==s: 15 | print("the amstrong numbers among the list are: ",element) 16 | 17 | else: 18 | print("there are no amstrong numbers in this list") -------------------------------------------------------------------------------- /Python Programs/send_email.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import smtplib 4 | import base64 5 | 6 | filename = "/tmp/test.txt" 7 | 8 | # Read a file and encode it into base64 format 9 | fo = open(filename, "rb") 10 | filecontent = fo.read() 11 | encodedcontent = base64.b64encode(filecontent) # base64 12 | 13 | sender = 'webmaster@tutorialpoint.com' 14 | reciever = 'amrood.admin@gmail.com' 15 | 16 | marker = "AUNIQUEMARKER" 17 | 18 | body =""" 19 | This is a test email to send an attachement. 20 | """ 21 | # Define the main headers. 22 | part1 = """From: From Person 23 | To: To Person 24 | Subject: Sending Attachement 25 | MIME-Version: 1.0 26 | Content-Type: multipart/mixed; boundary=%s 27 | --%s 28 | """ % (marker, marker) 29 | 30 | # Define the message action 31 | part2 = """Content-Type: text/plain 32 | Content-Transfer-Encoding:8bit 33 | 34 | %s 35 | --%s 36 | """ % (body,marker) 37 | 38 | # Define the attachment section 39 | part3 = """Content-Type: multipart/mixed; name=\"%s\" 40 | Content-Transfer-Encoding:base64 41 | Content-Disposition: attachment; filename=%s 42 | 43 | %s 44 | --%s-- 45 | """ %(filename, filename, encodedcontent, marker) 46 | message = part1 + part2 + part3 47 | 48 | try: 49 | smtpObj = smtplib.SMTP('localhost') 50 | smtpObj.sendmail(sender, reciever, message) 51 | print "Successfully sent email" 52 | except Exception: 53 | print "Error: unable to send email" 54 | -------------------------------------------------------------------------------- /Python Programs/stone_paper_scissors_game.py: -------------------------------------------------------------------------------- 1 | #this is the stone paper scissor game 2 | import random 3 | user=str(input('Enter your name ')) 4 | print(" ") 5 | computer_score=0 6 | user_score=0 7 | game_no=0 8 | list=['stone', 'paper', 'scissors'] 9 | print('you can chose s or p or z') 10 | print('you will be given 5 chances') 11 | print(" ") 12 | print('s : stone') 13 | print('p : paper') 14 | print('z : scissors') 15 | print(" ") 16 | while(game_no!=5): 17 | computer_turn=random.choice(list) 18 | print('your turn ') 19 | game_no+=1 20 | user_turn = str(input("you : ")) 21 | print("computer : ",computer_turn) 22 | print(" ") 23 | if(user_turn==computer_turn): 24 | user_score+=1 25 | computer_score+=1 26 | 27 | elif(user_turn=='s' and computer_turn=='paper'): 28 | computer_score+=1 29 | 30 | elif(user_turn=='s' and computer_turn=='scissors'): 31 | user_score+=1 32 | 33 | elif(user_turn=='p' and computer_turn=='stone'): 34 | user_score+=1 35 | 36 | elif(user_turn=='p' and computer_turn=='scissors'): 37 | computer_score+=1 38 | 39 | elif(user_turn=='z' and computer_turn=='stone'): 40 | computer_score+=1 41 | 42 | elif(user_turn=='z' and computer_turn=='paper'): 43 | user_score+=1 44 | 45 | print('YOUR SCORE : ',user_score) 46 | print('COMPUTER SCORE : ', computer_score) 47 | print(" ") 48 | if(user_score > computer_score): 49 | print("YAY YOU WON !!!!!!!") 50 | elif(user_score < computer_score): 51 | print("COMPUTER WON , BETTER LUCK NEXT TIME ") 52 | elif(user_score == computer_score): 53 | print("ITS A TIE ") 54 | -------------------------------------------------------------------------------- /Python Programs/stuckYourPC.py: -------------------------------------------------------------------------------- 1 | """ 2 | Programme to make your computer stuck 3 | """ 4 | from itertools import cycle 5 | x = [i for i in range(10)] 6 | for i in cycle(x): 7 | x.append(i) 8 | -------------------------------------------------------------------------------- /Python Programs/third.py: -------------------------------------------------------------------------------- 1 | def perfect(): 2 | n = int(input("Enter any number: ")) 3 | sum1 = 0 4 | for i in range(1, n): 5 | if (n % i == 0): 6 | sum1 = sum1 + i 7 | if (sum1 == n): 8 | print("The number is a Perfect number") 9 | else: 10 | print("The number is not a Perfect number") 11 | perfect() -------------------------------------------------------------------------------- /Python Programs/update_tuple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | tup1 = (12, 34.56); 4 | tup2 = ('abc', 'xyz'); 5 | 6 | # Following action is not valid for tuples 7 | # tup1[0] = 100; 8 | 9 | # So let's create a new tuple as follows 10 | tup3 = tup1 + tup2; 11 | print tup3; 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | -NO LONGER ACCEPTING ANY MORE PULL REQUEST! THANK YOU FOR PARTICIPATING- 2 | 3 | # Hacktoberfest 2022 4 | 5 | ## How to Participate? 6 | 1. First, Sign up on [Hacktoberfest 2022](https://hacktoberfest.com/) using your **GitHub** or **GitLab** Account 7 | 8 | ![image](https://user-images.githubusercontent.com/56226566/192785283-d6e00e40-6d26-43f0-bc2b-d03c4160298c.png) 9 | 10 | 2. Now that your account is created, Fork this Repository 11 | 12 | ![image](https://user-images.githubusercontent.com/56226566/192805525-211f3964-0585-4e0e-a47d-eea84a597fc8.png) 13 | 14 | 3. Now Upload your 4 PR's on the respected Folder and then Hit `Create a Pull Request` 15 | 16 | **Voila! You are Done! Now wait for the Maintainer to Accept your PR!** 17 | 18 | ------------------------------------------------------------------------------------------------------------------- 19 | ## Please avoid Spam and Invalid submissions 20 | 21 | ### Do not try to edit any Current Programs or Files 22 | -------------------------------------------------------------------------------- /Sprig Programs/README.md: -------------------------------------------------------------------------------- 1 | # Upload your Sprig JS Programs here. 2 | ### Please avoid Spam and Invalid submissions 3 | -------------------------------------------------------------------------------- /area: -------------------------------------------------------------------------------- 1 | a = 5 2 | b = 6 3 | c = 7 4 | 5 | s = (a + b + c) / 2 6 | 7 | area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 8 | print('The area of the triangle is %0.2f' %area) 9 | -------------------------------------------------------------------------------- /climbing stairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int totalways(int currentStair, int targetStair, unordered_map &memo) 4 | { 5 | if(currentStair==targetStair){ 6 | return 1; 7 | } 8 | 9 | if(currentStair > targetStair){ 10 | return 0; 11 | } 12 | int currentKey = currentStair; 13 | 14 | if(memo.find(currentKey)!=memo.end()){ 15 | return memo[currentKey]; 16 | } 17 | int oneStep = totalways (currentStair+1, targetStair, memo); 18 | int twoStep = totalways (currentStair+2, targetStair, memo); 19 | 20 | memo[currentkey] = oneStep+twoStep; 21 | 22 | return oneStep+twoStep; 23 | } 24 | 25 | int climbStairs (int n) { 26 | unordered_map memo; 27 | return totalways (0,n,memo); 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /temp.py: -------------------------------------------------------------------------------- 1 | cel = 37.5 2 | fahren = (cel * 1.8) + 32 3 | print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(cel,fahren)) 4 | --------------------------------------------------------------------------------