├── .vscode └── settings.json ├── Programming ├── Python │ ├── FactorialOfNumber │ │ └── factorial.py │ ├── ReverseofANumber │ │ └── ReverseofANumber.py │ ├── Reverse Integer │ │ └── reverse_integer.py │ ├── SumOfDigits │ │ └── SumOfDigits.py │ ├── Reverse Integer.py │ ├── CountWords │ │ └── Counting_words_starting_with_vowels.py │ ├── MatrixProduct │ │ └── matrix_product.py │ ├── DisplayPrimes │ │ └── DisplayPrimeArrayElements.py │ ├── TwoSum │ │ ├── Two Sum.py │ │ └── TwoSum.py │ ├── SwapNumber │ │ └── SwapNumber.py │ ├── Patterns │ │ ├── Pattern3.py │ │ ├── Pattern2.py │ │ └── Pattern1.py │ ├── AdditonOfDigitsOfAGivenNumber │ │ └── AdditonOfDigitsOfAGivenNumber.py │ ├── MatrixMean │ │ └── matrix_mean.py │ ├── Maximum Gap │ │ └── maximumGap.py │ ├── PrimeNumbersUptoN │ │ └── PrimeNumbersUptoN.py │ ├── Leibniz'sFormulaForCalculatingPi │ │ └── Leibniz'sFormulaForCalculatingPi.py │ ├── QuadraticEquation │ │ ├── QuadraticEq.py │ │ └── QuadraticEquationSolver.py │ ├── PalindromeNumber │ │ └── PalindromeNumber.py │ ├── RemoveDuplicates │ │ └── RemoveDuplicates.py │ ├── HighScorer │ │ ├── HighestScoringPlayer.py │ │ └── DisplayRunsScored.py │ ├── CountingOccurrenceOfEachWord │ │ └── CountingOccurrenceOfEachWord.py │ ├── KaperkerNumbers │ │ └── KaperkerNumbers.py │ ├── Reverse_Integer_python │ │ └── reverseInt.py │ ├── RomanToInteger │ │ └── RomanToInteger.py │ ├── GradingStudents │ │ └── gradingStudents.py │ ├── LengthOfLongestSubstring │ │ └── length_of_longest_substring_without_repeating_characters.py │ ├── CannyEdgeDetection │ │ └── CannyEdgeDetection.py │ ├── TriangleTripletsCounter │ │ └── TriangleTripletsCounter.py │ ├── Roman_to_Integer │ │ └── roman_to_integer.py │ ├── ModifiedKaprekarNumber │ │ └── ModifiedKaprekarNumber.py │ ├── LargestPalindromicSubstring │ │ └── largest_palindromic_substring.py │ ├── LetterCombinationsOfAPhoneNumber │ │ └── LetterCombinationsOfAPhoneNumber.py │ ├── CombinationSum │ │ └── combinationSum.py │ ├── GenerateParentheses │ │ └── GenerateParentheses.py │ ├── RootsOfQuadraticEquation │ │ └── RootsOfQuadraticEquation.py │ ├── MedianOfTwoSortedArrays │ │ └── median_of_two_sorted_arrays.py │ ├── anypalindrome │ │ └── anypalindrome.py │ ├── ContainerWithMostWater │ │ └── ContainerWithMostWater.py │ ├── MergeSortedArray │ │ └── merge_sorted_array.py │ ├── RotateArrayKTimes │ │ └── rotate_array.py │ ├── ReverseDoublyLinkedList │ │ └── ReverseDoublyLinkedList.py │ └── LinkedList │ │ └── LinkedList.py ├── JavaScript │ ├── BFS │ │ ├── 00.Node.js │ │ ├── 02.Queue.js │ │ ├── 04.BFS.js │ │ └── 03.Graph.js │ ├── Palindrome Number │ │ └── PalindromeNumber.js │ ├── Remove Duplicates │ │ └── RemoveDuplicates.js │ ├── LeibnizFormula │ │ └── LeibnizFormula.js │ ├── TwoSum │ │ ├── TwoSum.js │ │ └── TwoSum_2.js │ ├── DigitAddition │ │ └── digitAddition.js │ ├── MergeSortedArray │ │ └── mergeSortedArray.js │ ├── Maximum-Gap │ │ └── MaximumGap.js │ ├── Reverse-Integer │ │ └── reverseInteger.js │ ├── Bubblesort │ │ └── bubblesort.js │ ├── DigitsAddition │ │ └── DigitsAddition.js │ ├── Algorithm │ │ └── permutations.js │ ├── Kadanes-Algorithm │ │ └── KadanesAlgorithm.js │ ├── SelectionSort │ │ └── selectionsort.js │ ├── GenerateParenthesis │ │ └── generateParenthesis.js │ ├── ContainerWithMostWater │ │ └── containerWithMostWater.js │ ├── CombinationSum │ │ └── combinationSum.js │ ├── Merge-Sort │ │ └── mergeSort.js │ ├── Zigzag-Conversion │ │ └── zigzagConversion.js │ ├── LetterCombinationsofaPhoneNumber │ │ └── LetterCombinationsofaPhoneNumber.js │ ├── MaximumGap │ │ └── Maximumgap.js │ └── Luhn │ │ └── luhnAlogorithm.js ├── Java │ ├── Zoo │ │ ├── Readme.md │ │ └── Zoo.java │ ├── MergeSortedArray │ │ └── MergeSortedArray.java │ ├── CountDigits │ │ ├── CountDigit2.java │ │ └── CountDigits.java │ ├── TemperatureConversion │ │ ├── CelciusToFarenheit.java │ │ ├── ConvertCelciusToFahrenheit.java │ │ ├── CelciusToFahrenheit.java │ │ └── ConvertCelsiusIntoFahrenheit.java │ ├── RemoveDuplicatesFromSortedArray │ │ └── RemoveDuplicatesFromSortedArray.java │ ├── LeibnizFormula │ │ └── LeibnizFormula.java │ ├── Suffle Array │ │ └── ShuffleArray.java │ ├── ReverseString │ │ └── ReverseString.java │ ├── AddDigitsOfNumber │ │ └── AddDigitsOfNumber.java │ ├── ReverseInteger │ │ └── ReverseInteger.java │ ├── ReverseNumber │ │ └── ReverseNumber.java │ ├── Fibonacci │ │ └── FibonacciSeries.java │ ├── DistanceBetweenBusStops │ │ └── DistanceBetweenBusStops.java │ ├── Container With Most Water │ │ ├── containerWithMostWater.txt │ │ └── containerWithMostWater.java │ ├── PalindromeOrNot │ │ ├── PalindromeCheck.java │ │ ├── PalindromeChecker.java │ │ └── PalindromeOrNot.java │ ├── Porcupine │ │ └── Porcupine.java │ ├── EvenOrOdd │ │ └── EvenOrOdd.java │ ├── CheckPrime │ │ ├── CheckPrime.java │ │ └── PrimeNumbers.java │ ├── Iterator │ │ └── Iterator.java │ ├── FizzBuzz │ │ └── FizzBuzz.java │ ├── TowerOfHanoi │ │ └── TowerOfHanoi.java │ ├── PrimeChecker │ │ └── PrimeChecker.java │ ├── Palindrome │ │ ├── StringPalindrome.java │ │ ├── Palindrome.java │ │ └── palindrome.java │ ├── PalinPairs │ │ └── PalinPairs.java │ ├── KLargestElements │ │ └── KLargestElements.java │ ├── NumberSquare │ │ └── NumberSquare.java │ ├── HighestFrequencyCharacter │ │ └── HighestFrequencyCharacter.java │ ├── TriangleTripletsCounter │ │ └── TriangleTripletsCounter.java │ ├── WordsStartWithVowels │ │ └── CountingTheWordsStartingWithVowels.java │ ├── AnagramsOrNot │ │ ├── AnagramsOrNot.java │ │ ├── TwoStringsAnagrams.java │ │ └── IsAnagram.java │ ├── PassOrFail │ │ └── PassOrFail.java │ ├── DutchNationalFlag │ │ └── DutchNationalFlag.java │ ├── Two Sum │ │ └── Two_Sum.java │ ├── GenerateParanthese │ │ └── GenerateParentheses.java │ ├── HighScorer │ │ └── DisplayHighestRunsScored.java │ ├── MergeSort │ │ └── MergeSort.java │ ├── Integer to Roman │ │ └── IntegertoRoman.java │ ├── LongestPalindromicSubstring │ │ └── LongestPalindromicSubstring.java │ ├── RemoveDuplicates │ │ └── removeduplicates.java │ ├── DisplayPrimes │ │ └── DisplayPrimeArrayElements.java │ ├── MedianOfTwoSortedArrays │ │ └── MedianOfTwoSortedArrays.java │ ├── CheckPsswdStrongOrNot │ │ └── StrongPsswd.java │ ├── DiceThrowProblem │ │ └── Dice_Throw_Problem.java │ ├── RotateKLeftKRight │ │ └── RotateKLeftKRight.java │ ├── container_with_most_water │ │ └── ContainerWithMostWater.java │ ├── MinimumPartitionProblem │ │ └── MinimumPartitionProblem.java │ ├── GoldMineProblem │ │ └── Gold_Mine_Problem.java │ ├── Luhn'sAlgorithm │ │ └── README.md │ ├── Maximum Gap │ │ └── MaximumGap.java │ └── IsYourPasswordStrong │ │ └── checkStrongPassword.java ├── C++ │ ├── DecimalToBinary │ │ └── decimaltobinary.cpp │ ├── LongestSubSequenceWithoutRepeatingCharacters │ │ └── longestSubsequence.py │ ├── Fibonacci │ │ └── Fibonacci.cpp │ ├── isPallindrome │ │ ├── numberPalindrome.cpp │ │ └── isPallindrome.cpp │ ├── Palindrome │ │ └── palindrome.cpp │ ├── Palindrome_Number │ │ └── Palindromenumber.cpp │ ├── SumOfDigits │ │ └── SumOfDigits.cpp │ ├── RearrangeArrayO(1)ExtraSpace │ │ └── RearrangeArrayO(1)ExtraSpace.cpp │ ├── ReverseInteger │ │ └── reverse_signed_integer.cpp │ ├── isPrime │ │ └── isPrime.cpp │ ├── TowerOfHanoi │ │ └── tower_Of_Hanoi.cpp │ ├── LeibnizFormula │ │ └── LeibnizFormula.cpp │ ├── IsPrime │ │ └── CheckthenumberisPrimeOrNot.cpp │ ├── BalanceStrings │ │ └── BalanceStrings.cpp │ ├── WordsStartingWithVowels │ │ ├── CountTheWordsStartingWithVowels.cpp │ │ └── WordsStartWithVowels2.cpp │ ├── HighestScorer │ │ ├── HighScorer2.cpp │ │ └── HighestScorer.cpp │ ├── DisplayPrimeArrayElements │ │ └── DisplayPrimeArrayElements.cpp │ ├── Generate Parenthesis │ │ ├── Generate Parenthesis.cpp │ │ └── parenthesesCombinations.cpp │ ├── SinglyLinkedList │ │ └── Linkedlist.cpp │ ├── Integer_to_Roman │ │ └── INTEGER_TO_ROMAN.cpp │ ├── LuhnAlgorithm │ │ └── luhn's_algorithm.cpp │ ├── TopologicalSorting │ │ └── TopologicalSorting.cpp │ ├── PrimeGame │ │ └── Prime_Game.cpp │ ├── PassStrengthChecker │ │ └── CheckPassStrength.cpp │ ├── CombinationSum │ │ └── CombinationSum.cpp │ ├── PossibleSum │ │ └── Possible_sum.cpp │ ├── Anagram │ │ └── Anagram.cpp │ ├── Checking_duplicate_in_a_sorted _array │ │ └── Remove_Duplicates_from_Sorted_Array.cpp │ ├── Roman_To_Integer │ │ └── Roman_To_Integer.cpp │ ├── LinearSearch │ │ └── linearSearch.cpp │ ├── MissingElement │ │ └── ME.cpp │ ├── Kadanes │ │ └── kadane.cpp │ ├── ActivitySelection │ │ └── ActivitySelection.cpp │ ├── Maximum_Gap │ │ ├── MaximumGap.cpp │ │ └── Maximum_Gap.cpp │ ├── TravellingSalesmanProblem │ │ └── Travelling_salesman_problem_bit-masking.cpp │ ├── MergeSortedArray │ │ └── MergeSortedArrays.cpp │ ├── Two Sum │ │ └── Two_Sum.cpp │ ├── LetterCombinationofaPhoneNumber │ │ └── letterCombination.cpp │ ├── LongestPalindromicSubstring │ │ └── LongestPalindromicSubstring.cpp │ ├── Tries │ │ └── Memory Efficient trie implementation.cpp │ └── SortedLinkedList │ │ └── SortedLinkedList.cpp ├── C# │ ├── Generate Parentheses │ │ ├── readme.md │ │ └── solution.cs │ ├── CountVowels │ │ └── CountVowels.cs │ ├── SwappingTwoNumbers │ │ └── SwappingTwoNumbers.c │ ├── Combination Sum │ │ └── readme.md │ ├── RemoveDuplicatesFromSortedArr │ │ └── RemoveDuplicatesFromSortedArr.cs │ ├── ReverseInteger │ │ └── ReverseInteger.cs │ ├── CheckForPalindrome │ │ └── Palindrome.cs │ ├── Pallindrome │ │ └── Pallindrome.cs │ ├── PhoneLetterCombo │ │ └── README.md │ ├── MaximumGap │ │ └── MaximumGap.cs │ ├── longest_substring │ │ └── longest substring.cs │ └── IntegerToRoman │ │ └── IntegerToRoman.cs ├── C │ ├── Palindrome Number │ │ └── palindrome_number.c │ ├── LeibnizFormula │ │ └── LeibnizFormula.c │ ├── Two Sum │ │ └── TwoSum.c │ ├── Integer_To_Roman │ │ └── integer_to_roman.c │ ├── BinarySearch │ │ └── Binary_Search.c │ ├── Two sum │ │ └── TwoSum.cpp │ ├── Palindrome │ │ └── palindrome.c │ ├── Generate Parenthesis │ │ └── Generate_parenthesis.c │ ├── Anagram │ │ └── anagram.c │ ├── Merging Two sorted Arrays │ │ └── MergingSortedArrays.c │ └── Median of Two Sorted Arrays │ │ └── medianoftwosortedarrays.c ├── Golang │ ├── PalindromeNumber │ │ ├── palindrome_number_test.go │ │ └── palindrome_number.go │ ├── PlayerRecord │ │ └── PlayerRecord.go │ ├── DisplayPrime │ │ └── DisplayPrimeArrayElementsInput.go │ ├── Roman_to_Integer │ │ └── roman_to_integer.go │ ├── WordsStartWithVowels │ │ └── WordsStartWithVowels.go │ ├── RemoveDuplicatesFromSortedArray │ │ └── RemoveDuplicatesFromSortedArray.go │ ├── TwoSum │ │ └── TwoSum.go │ ├── GenerateParentheses │ │ └── GenerateParentheses.go │ └── ContainerWithMostWater │ │ └── container_with_most_water.go └── Kotlin │ ├── PalindromeNumber │ └── PalindromeNumber.kt │ ├── TwoSum │ └── TwoSum.kt │ └── RemoveDuplicates │ └── RemoveDuplicates.kt └── .github └── ISSUE_TEMPLATE ├── question-expecting-c-solution.md ├── question-expecting-c#-solution.md ├── question-expecting-c++-solution.md ├── question-expecting-java-solution.md ├── question-expecting-golang-solution.md ├── question-expecting-kotlin-solution.md ├── question-expecting-python-solution.md ├── question-expecting-javascript-solution.md ├── feature_request.md └── bug_report.md /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "iostream": "cpp" 4 | } 5 | } -------------------------------------------------------------------------------- /Programming/Python/FactorialOfNumber/factorial.py: -------------------------------------------------------------------------------- 1 | def factorial(n): 2 | if (n == 0): 3 | return 1 4 | else: 5 | return n * factorial(n - 1) -------------------------------------------------------------------------------- /Programming/Python/ReverseofANumber/ReverseofANumber.py: -------------------------------------------------------------------------------- 1 | n=input("Enter the number to be reversed") 2 | for i in range((len(n)-1),-1,-1): 3 | print(n[i],end="") 4 | -------------------------------------------------------------------------------- /Programming/Python/Reverse Integer/reverse_integer.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | s=str(n) 3 | s=s[::-1] 4 | if n>=0: 5 | print(int(s)) 6 | else: 7 | print('-',end="") 8 | print(int(s[:-1])) -------------------------------------------------------------------------------- /Programming/JavaScript/BFS/00.Node.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = class Node { 3 | constructor(data) { 4 | this.data = data; 5 | this.nextElement = null; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /Programming/Java/Zoo/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | Zoo Management Application 3 | 4 | Created By- Yasas Sandeepa 5 | Undergratuate 6 | Bsc(Hons) in Information Technology 7 | University of Moratuwa 8 | Sri Lanka 9 | 10 | -------------------------------------------------------------------------------- /Programming/Python/SumOfDigits/SumOfDigits.py: -------------------------------------------------------------------------------- 1 | n=int(input("Enter the number:")) 2 | sum=0 3 | while n!=0 : 4 | m=n%10 5 | n=n/10 6 | sum=int(sum+m) 7 | print("Sum of digits of the number entered: ", sum) -------------------------------------------------------------------------------- /Programming/Python/Reverse Integer.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | i= int(input("Enter your number: ")) 4 | 5 | rev = 0 6 | 7 | while(i>0): 8 | rev = (rev*10) + i%10 9 | i = i//10 10 | 11 | print(rev) 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Programming/Python/CountWords/Counting_words_starting_with_vowels.py: -------------------------------------------------------------------------------- 1 | a = str(input("Enter string : ")) 2 | b = a.split(" ") 3 | c=0 4 | for i in b: 5 | if(i[0] in ('AEIOUaeiou')): 6 | c=c+1 7 | print("Count of words starting with vowels : ",c) -------------------------------------------------------------------------------- /Programming/Python/MatrixProduct/matrix_product.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | # matrix product using reduce, lambda 3 | mat = [[1, 4, 5], [7, 3], [4], [46, 7, 3]] 4 | prod = reduce(lambda a,b:a*b, [j for i in mat for j in i]) 5 | 6 | print(prod) 7 | -------------------------------------------------------------------------------- /Programming/Python/DisplayPrimes/DisplayPrimeArrayElements.py: -------------------------------------------------------------------------------- 1 | #Contributed by @ss2808 2 | arr = list(map(int,input("Enter any 20 elements in the array: ").strip().split())) 3 | for i in range(20): 4 | if(isprime(value)==True): 5 | print(a[i], " is prime", end='') 6 | -------------------------------------------------------------------------------- /Programming/JavaScript/Palindrome Number/PalindromeNumber.js: -------------------------------------------------------------------------------- 1 | function isPalindrome(n){ 2 | const num = n.toString().split('').join(''); 3 | const revNum = n.toString().split('').reverse().join(''); 4 | 5 | if(num[0] === '-') return false; 6 | return num === revNum; 7 | } -------------------------------------------------------------------------------- /Programming/JavaScript/Remove Duplicates/RemoveDuplicates.js: -------------------------------------------------------------------------------- 1 | function removeDuplicate(arr) { 2 | let n = 0; 3 | for(let i = 1; i <= arr.length; i++){ 4 | if(arr[n] - arr[i] !== 0) { 5 | arr[n+1] = arr[i]; 6 | n++; 7 | } 8 | } 9 | return arr; 10 | } -------------------------------------------------------------------------------- /Programming/Python/TwoSum/Two Sum.py: -------------------------------------------------------------------------------- 1 | def twoSum(numbers, target): 2 | for i, num in enumerate(numbers): 3 | for j, numb in enumerate(numbers): 4 | if i == j: 5 | continue 6 | elif num + numb == target: 7 | return [i+1,j+1] 8 | -------------------------------------------------------------------------------- /Programming/Python/SwapNumber/SwapNumber.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter the value of a : ")) 2 | b = int(input("Enter the value od b : ")) 3 | 4 | a = a+b # sum of both 5 | b = a-b # subtracting value b from sum to get the value of a 6 | a = a-b # subtracting value a from sum to get the value of b 7 | 8 | print(a,b) 9 | 10 | -------------------------------------------------------------------------------- /Programming/Java/MergeSortedArray/MergeSortedArray.java: -------------------------------------------------------------------------------- 1 | class MergeSortedArray { 2 | public void merge(int[] nums1, int m, int[] nums2, int n) { 3 | int i=m; 4 | for(int j=0;j Math.pow(-1, k) / (2 * k + 1); 2 | 3 | const leibniz = k => { 4 | let sum = 0; 5 | for (let i = 0; i < k; i++) { 6 | sum += leibnizStep(i); 7 | } 8 | 9 | return sum * 4; 10 | }; 11 | 12 | console.log(leibniz(10000)); 13 | -------------------------------------------------------------------------------- /Programming/Java/CountDigits/CountDigit2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class CountDigit2 3 | { 4 | public static void main(String[] args) { 5 | int num; 6 | Scanner sc = new Scanner(System.in); 7 | num = sc.nextInt(); 8 | System.out.println(Integer.toString(num).length()); 9 | } 10 | } -------------------------------------------------------------------------------- /Programming/JavaScript/TwoSum/TwoSum.js: -------------------------------------------------------------------------------- 1 | const twoSum = (nums, target) => { 2 | const map = {}; 3 | let complement; 4 | for (let i = 0; i < nums.length; i++) { 5 | complement = target - nums[i]; 6 | if (map.hasOwnProperty(complement)) { 7 | return [i, map[complement]] 8 | } 9 | map[nums[i]] = i; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-c-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting C solution 3 | about: Question expecting C solution 4 | title: "[C-Solution required]" 5 | labels: good first issue, Hacktoberfest, C/C++ 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /Programming/JavaScript/DigitAddition/digitAddition.js: -------------------------------------------------------------------------------- 1 | var digitAddition = (num) => { 2 | 3 | if(isNaN(parseInt(num))) { 4 | return 0; 5 | } 6 | return num.toString().split("").reduce((acc, item) => parseInt(acc) + parseInt(item)); 7 | } 8 | 9 | digitAddition(152); // returns 8 10 | digitAddition("not a number"); // returns 0 -------------------------------------------------------------------------------- /Programming/Python/Patterns/Pattern3.py: -------------------------------------------------------------------------------- 1 | #Contributed by Pankaj 2 | #Downward asterisk(*) pattern 3 | rows = 5 4 | k = 2 * rows - 2 5 | for i in range(rows, -1, -1): 6 | for j in range(k, 0, -1): 7 | print(end=" ") 8 | k = k + 1 9 | for j in range(0, i + 1): 10 | print("*", end=" ") 11 | print("") 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-c#-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting C# solution 3 | about: Question expecting C# solution 4 | title: "[C#-Solution required]" 5 | labels: good first issue, Hacktoberfest, C# 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-c++-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting C++ solution 3 | about: Question expecting C++ solution 4 | title: "[C++-Solution required]" 5 | labels: good first issue, Hacktoberfest, C/C++ 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /Programming/Java/TemperatureConversion/CelciusToFarenheit.java: -------------------------------------------------------------------------------- 1 | public class CelciusToFarenheit 2 | { 3 | public static void main (String args[]) 4 | { float Fahrenheit, Celsius; 5 | Celsius= 13; 6 | Fahrenheit =((Celsius*9)/5)+32; 7 | System.out.println("Temperature in Fahrenheit is: "+Fahrenheit); 8 | }} -------------------------------------------------------------------------------- /Programming/Python/AdditonOfDigitsOfAGivenNumber/AdditonOfDigitsOfAGivenNumber.py: -------------------------------------------------------------------------------- 1 | # Python program to 2 | # compute sum of digits in 3 | # number. 4 | 5 | # Function to get sum of digits 6 | 7 | def getSum(n): 8 | sum = 0 9 | for digit in str(n): 10 | sum += int(digit) 11 | return sum 12 | 13 | n = 12345 14 | print(getSum(n)) 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-java-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting Java solution 3 | about: Question expecting Java solution 4 | title: "[Java-Solution required]" 5 | labels: good first issue, Hacktoberfest, Java 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-golang-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting Golang solution 3 | about: Question expecting Golang solution 4 | title: "[Golang-Solution required]" 5 | labels: good first issue, Hacktoberfest, Golang 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-kotlin-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting Kotlin solution 3 | about: Question expecting Kotlin solution 4 | title: "[Kotlin-Solution required]" 5 | labels: good first issue, Hacktoberfest, Kotlin 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-python-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting Python solution 3 | about: Question expecting Python solution 4 | title: "[Python-Solution required]" 5 | labels: good first issue, Hacktoberfest, Python 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question-expecting-javascript-solution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question expecting Javascript solution 3 | about: Question expecting Javascript solution 4 | title: "[Javascript-Solution required]" 5 | labels: good first issue, Hacktoberfest, Javascript 6 | assignees: '' 7 | 8 | --- 9 | 10 | Provide an ample explanation of the question. 11 | Give example if possible. 12 | -------------------------------------------------------------------------------- /Programming/C++/DecimalToBinary/decimaltobinary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std ; 3 | 4 | int main() 5 | { 6 | int n ; 7 | cin>>n; 8 | for (int i = 31; i >= 0; i--) { 9 | int k = n >> i; 10 | if (k & 1) 11 | cout << "1"; 12 | else 13 | cout << "0"; 14 | } 15 | cout << endl ; 16 | 17 | } -------------------------------------------------------------------------------- /Programming/JavaScript/MergeSortedArray/mergeSortedArray.js: -------------------------------------------------------------------------------- 1 | const merge = function (nums1, m, nums2, n) { 2 | var insertPos = m + n - 1; 3 | m--; n--; 4 | while (n >= 0) { 5 | nums1[insertPos--] = (nums1[m] > nums2[n]) ? nums1[m--] : nums2[n--]; 6 | } 7 | }; 8 | 9 | //sample-test 10 | let nums1 = [1,2,3,0,0,0]; 11 | merge(nums1,3,[2,5,6],3); 12 | console.log(nums1); -------------------------------------------------------------------------------- /Programming/Python/MatrixMean/matrix_mean.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | # matrix mean 3 | def matrix_mean(mat): 4 | 5 | flatten = [j for i in mat for j in i] 6 | sum = reduce(lambda a,b:a+b,flatten) 7 | # print(sum) 8 | return sum/len(flatten) 9 | 10 | mat = [[5,6,7] , [7,5,6]] 11 | print(matrix_mean(mat)) 12 | mat = [[5, 6, 7, 4, 8]] 13 | print(matrix_mean(mat)) 14 | -------------------------------------------------------------------------------- /Programming/Python/Maximum Gap/maximumGap.py: -------------------------------------------------------------------------------- 1 | 2 | def max(a, b): 3 | if a 1: 8 | for i in range(2, int(num/2) + 1): 9 | if (num % i) == 0: 10 | break 11 | else: 12 | print(num ,end=" ") 13 | -------------------------------------------------------------------------------- /Programming/C++/LongestSubSequenceWithoutRepeatingCharacters/longestSubsequence.py: -------------------------------------------------------------------------------- 1 | string = input() 2 | seen = {} 3 | maximum_length = 0 4 | start = 0 5 | 6 | for end in range(len(string)): 7 | if string[end] in seen: 8 | start = max(start, seen[string[end]] + 1) 9 | seen[string[end]] = end 10 | maximum_length = max(maximum_length, end-start + 1) 11 | 12 | print(maximum_length) -------------------------------------------------------------------------------- /Programming/JavaScript/Maximum-Gap/MaximumGap.js: -------------------------------------------------------------------------------- 1 | function maximumGap(arr) { 2 | let max = 0; 3 | if (arr.length >= 2) { 4 | arr.sort((a, b) => a - b); 5 | 6 | for (let i in arr) { 7 | const diff = arr[i] - arr[i - 1]; 8 | 9 | if (diff > max) { 10 | max = diff; 11 | } 12 | } 13 | 14 | } 15 | return max; 16 | } 17 | 18 | const arr = [1, 30, 4, 21, 10]; 19 | console.log(maximumGap(arr)); 20 | -------------------------------------------------------------------------------- /Programming/JavaScript/Reverse-Integer/reverseInteger.js: -------------------------------------------------------------------------------- 1 | function reverseInteger(num) { 2 | let signed = 1; 3 | 4 | if(+num < 0) { 5 | signed = -1; 6 | num = signed * num; 7 | } 8 | 9 | const digitsArray = num.toString().split(''); 10 | digitsArray.reverse(); 11 | 12 | return +digitsArray.join('') * signed; 13 | } 14 | 15 | // Test 16 | const num = 123; 17 | console.log(reverseInteger(num)); 18 | -------------------------------------------------------------------------------- /Programming/Python/Leibniz'sFormulaForCalculatingPi/Leibniz'sFormulaForCalculatingPi.py: -------------------------------------------------------------------------------- 1 | def myPi(n): 2 | denominator = 1 3 | addto = 1 4 | 5 | for i in range(n): 6 | denominator = denominator + 2 7 | addto = addto - (1/denominator) 8 | denominator = denominator + 2 9 | addto = addto + (1/denominator) 10 | 11 | pi = addto * 4 12 | 13 | return(pi) 14 | 15 | print(myPi(1000000)) -------------------------------------------------------------------------------- /Programming/Python/Patterns/Pattern2.py: -------------------------------------------------------------------------------- 1 | #Contributed by @Hinal-Srivastava 2 | 3 | #Alphabetical Equilateral Triangle 4 | size = 7 5 | asciiNumber = 65 6 | m = (2 * size) - 2 7 | for i in range(0, size): 8 | for j in range(0, m): 9 | print(end=" ") 10 | m = m - 1 11 | for j in range(0, i + 1): 12 | character = chr(asciiNumber) 13 | print(character, end=' ') 14 | asciiNumber += 1 15 | print(" ") -------------------------------------------------------------------------------- /Programming/Python/QuadraticEquation/QuadraticEq.py: -------------------------------------------------------------------------------- 1 | # Solve the quadratic equation ax**2 + bx + c = 0 2 | 3 | # import complex math module 4 | import cmath 5 | 6 | a = 1 7 | b = 5 8 | c = 6 9 | 10 | # calculate the discriminant 11 | d = (b**2) - (4*a*c) 12 | 13 | # find two solutions 14 | ans1 = (-b-cmath.sqrt(d))/(2*a) 15 | ans2 = (-b+cmath.sqrt(d))/(2*a) 16 | 17 | print('The solution are {0} and {1}'.format(ans1,ans2)) -------------------------------------------------------------------------------- /Programming/C#/Generate Parentheses/readme.md: -------------------------------------------------------------------------------- 1 | # 22. Generate Parentheses 2 | 3 | Given *n* pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 4 | 5 | For example, given *n* = 3, a solution set is: 6 | ``` 7 | [ 8 | "((()))", 9 | "(()())", 10 | "(())()", 11 | "()(())", 12 | "()()()" 13 | ] 14 | ``` 15 | 16 | ### Example 1: 17 | ``` 18 | Input: 2 19 | 20 | Output: ["(())","()()"] 21 | ``` -------------------------------------------------------------------------------- /Programming/Java/RemoveDuplicatesFromSortedArray/RemoveDuplicatesFromSortedArray.java: -------------------------------------------------------------------------------- 1 | public class RemoveDuplicatesFromArray { 2 | public int removeDuplicates(int[] nums) { 3 | int i=1; 4 | if(nums.length==0) { 5 | i=0; 6 | } 7 | else { 8 | for(int j=1;j split[j+1]){ 8 | temp = split[j]; 9 | split[j] = split[j+1]; 10 | split[j+1] = temp; 11 | } 12 | } 13 | } 14 | return split.join(' '); 15 | } 16 | 17 | bubbleSort([9, 7, 5, 3, 1, 2, 4, 6, 8]); -------------------------------------------------------------------------------- /Programming/Python/HighScorer/HighestScoringPlayer.py: -------------------------------------------------------------------------------- 1 | numPlayers = 11 2 | highestScore = 0 3 | hPlayerName = "" 4 | for p in range(numPlayers): 5 | pname = input("Please enter Player's name:") 6 | pscore = int(input("Please enter Player's score:")) 7 | if pscore > highestScore: 8 | highestScore = pscore 9 | hPlayerName = pname 10 | 11 | print("Player who scored highest runs: " + hPlayerName) 12 | print("And player's score is: " + str(highestScore)) 13 | -------------------------------------------------------------------------------- /Programming/C++/Fibonacci/Fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n1=0,n2=1,n3,i,number; 5 | cout<<"Enter the number of elements: "; 6 | cin>>number; 7 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int num,r,sum=0,temp; 6 | cout<<"Enter the Number: "; 7 | cin>>num; 8 | temp=num; 9 | while(num>0) 10 | { 11 | r=num%10; 12 | sum=(sum*10)+r; 13 | num=num/10; 14 | } 15 | if(temp==sum) 16 | cout<<"Palindrome Number"; 17 | else 18 | cout<<"Not Palindrome Number"; 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Programming/JavaScript/DigitsAddition/DigitsAddition.js: -------------------------------------------------------------------------------- 1 | const main = () => { 2 | const input = 254; 3 | const output = sumDigits(input); 4 | console.log(output); 5 | return output; 6 | }; 7 | 8 | const sumDigits = (input) => { 9 | const inputString = input.toString(); 10 | let subOfDigits = 0; 11 | for (let index = 0; index < inputString.length; index++) { 12 | subOfDigits += parseInt(inputString.charAt(index)); 13 | } 14 | return subOfDigits; 15 | }; 16 | 17 | main(); 18 | -------------------------------------------------------------------------------- /Programming/Python/CountingOccurrenceOfEachWord/CountingOccurrenceOfEachWord.py: -------------------------------------------------------------------------------- 1 | 2 | # Program to find the number of occurrence of each unique word in the sequence of occurrence of each word. 3 | 4 | from collections import Counter 5 | 6 | if __name__ == '__main__': 7 | n = int(input()) 8 | w = [] 9 | for i in range(n): 10 | x = input() 11 | w.append(x) 12 | c = Counter(w) 13 | l = len(c) 14 | print(l) 15 | v = c.values() 16 | for i in v: 17 | print(i, end=' ') 18 | -------------------------------------------------------------------------------- /Programming/Java/LeibnizFormula/LeibnizFormula.java: -------------------------------------------------------------------------------- 1 | public class LeibnizFormula { 2 | 3 | public static void main(String[] args) { 4 | System.out.println(leibniz(100000)); 5 | } 6 | 7 | public static double leibniz(int k) { 8 | double sum = 0; 9 | for(int i=0; i0){ 10 | countDigit++; 11 | temp=temp/10; 12 | } 13 | System.out.println("The number - "+number + " has - "+ countDigit+" digits."); 14 | sc.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Programming/Java/TemperatureConversion/ConvertCelciusToFahrenheit.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class ConvertCelciusToFahrenheit { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Enter a temperature in degrees Celcius: "); 7 | Double tempC = input.nextDouble(); 8 | Double tempF = (tempC * 1.8) + 32; 9 | System.out.println(tempC.toString() + " degrees Celcius = " + tempF.toString() + " degrees Fahrenheit."); 10 | } 11 | } -------------------------------------------------------------------------------- /Programming/C++/Palindrome/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n, reversedN = 0, remainder, originalN; 5 | cin >> n; 6 | originalN = n; 7 | while (n != 0) { 8 | remainder = n % 10; 9 | reversedN = reversedN * 10 + remainder; 10 | n /= 10; 11 | } 12 | 13 | if (originalN == reversedN) 14 | printf("%d is a palindrome.", originalN); 15 | else 16 | printf("%d is not a palindrome.", originalN); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Programming/C++/Palindrome_Number/Palindromenumber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int x, rev = 0, rem, ori; 9 | cout<<"Enter an integer: "; 10 | cin>>x; 11 | 12 | ori=x; 13 | while (x != 0) 14 | { 15 | rem = x % 10; 16 | rev = rev * 10 + rem; 17 | x /= 10; 18 | } 19 | 20 | if (ori>0) 21 | { 22 | 23 | if(ori==rev) 24 | cout<<"True"; 25 | else 26 | cout<<"False"; 27 | } 28 | else 29 | { 30 | cout<<"False"; 31 | 32 | } 33 | return 0; 34 | 35 | 36 | } -------------------------------------------------------------------------------- /Programming/C/Palindrome Number/palindrome_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n, m, rever = 0, rex; 4 | printf("Enter any number: "); 5 | scanf("%d", &n); 6 | m = n; 7 | if(n<0) 8 | { printf("false"); } 9 | else{ 10 | //logic 11 | while (n > 0){ 12 | rex = n % 10; 13 | rever = rever * 10 + rex; 14 | n = n / 10; 15 | } 16 | if (m == rever) 17 | { printf("true"); } 18 | else 19 | { printf("false"); } 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Programming/Java/Suffle Array/ShuffleArray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] shuffle(int[] nums, int n) { 3 | int max = 1001; // M in the above explanation 4 | 5 | for(int i=n;i 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n , rem , sum = 0; 9 | 10 | cout<<"Enter the number: \n"; 11 | cin>>n; 12 | 13 | while(n > 0) 14 | { 15 | rem = n % 10; // extracting the last digit 16 | n = n / 10; // removing the last digit 17 | sum = sum + rem; // calculating sum of digits 18 | } 19 | 20 | cout<<"Sum of digits of the number entered: "< 2 | using namespace std; 3 | 4 | // Function to rarrange the elements in O(1) extra space 5 | void arrange(long long A[], int n1) { 6 | int i; 7 | 8 | // changing the array elements 9 | for(i=0;i0 ; i++){ 13 | 14 | ans += num % 10; 15 | num /= 10; 16 | } 17 | 18 | System.out.println("Sum of Digits of "+n+" = "+ans); 19 | s.close(); 20 | } 21 | } -------------------------------------------------------------------------------- /Programming/C++/isPallindrome/isPallindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, num, digit, rev = 0; 7 | 8 | cout << "Enter a number: "; 9 | cin >> num; 10 | 11 | n = num; 12 | 13 | do 14 | { 15 | digit = num % 10; 16 | rev = (rev * 10) + digit; 17 | num = num / 10; 18 | } while (num != 0); 19 | 20 | if (n == rev) 21 | cout << " The number is a palindrome."; 22 | else 23 | cout << " The number is not a palindrome."; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Programming/Java/ReverseInteger/ReverseInteger.java: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/reverse-integer/ 2 | class Solution { 3 | public int reverse(int x) { 4 | int rev = 0; 5 | while(x!=0) 6 | { 7 | int r = x%10; 8 | x=x/10; 9 | if(rev> Integer.MAX_VALUE/10 ||rev == Integer.MAX_VALUE/10 && r > 7) 10 | return 0; 11 | if(rev< Integer.MIN_VALUE/10 ||rev == Integer.MIN_VALUE/10 && r > 8) 12 | return 0; 13 | rev=rev*10+r; 14 | } 15 | return rev; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Programming/C#/CountVowels/CountVowels.cs: -------------------------------------------------------------------------------- 1 | static void Main() 2 | { 3 | int total = 0; 4 | // Build a list of vowels up front: 5 | var vowels = new HashSet { 'a', 'e', 'i', 'o', 'u' }; 6 | 7 | Console.WriteLine("Enter a Sentence"); 8 | string sentence = Console.ReadLine().ToLower(); 9 | 10 | for (int i = 0; i < sentence.Length; i++) 11 | { 12 | if (vowels.Contains(sentence[i])) 13 | { 14 | total++; 15 | } 16 | } 17 | Console.WriteLine("Your total number of vowels is: {0}", total); 18 | 19 | Console.ReadLine(); 20 | } -------------------------------------------------------------------------------- /Programming/C++/ReverseInteger/reverse_signed_integer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int reverse_digits(int num); 4 | 5 | int main() { 6 | int num; 7 | cout << "\nEnter an Integer : "; 8 | cin >> num; 9 | cout << "\nInput Integer : " << num; 10 | cout << "\nReversed Integer : " << reverse_digits(num) << "\n\n"; 11 | 12 | return 0; 13 | } 14 | int reverse_digits(int num) { 15 | int rev_num = 0; 16 | while (num > 0) { 17 | rev_num = rev_num*10 + num%10; 18 | num = num/10; 19 | } 20 | return rev_num; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Programming/C++/isPrime/isPrime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool checkPrime(int n) { 6 | if(n<=1){ 7 | return false; 8 | } 9 | int i; 10 | for(i = 2; i*i <= n; i++) { // O(sqrt(n)) 11 | if (n%i == 0) 12 | { 13 | return false; 14 | } 15 | } 16 | return true; 17 | } 18 | 19 | int main() { 20 | int input; 21 | cout<<"Enter a number:"; 22 | cin>>input; 23 | 24 | if(checkPrime(input)){ 25 | cout<<"Prime Number"; 26 | } 27 | else{ 28 | cout<<"Not Prime"; 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Programming/Golang/PlayerRecord/PlayerRecord.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main(){ 6 | 7 | var player[11]string 8 | var run[11]int 9 | var max int=0 10 | var index int 11 | 12 | for i:=0;i<11;i++{ 13 | fmt.Print(i+1,". Player Name:") 14 | fmt.Scan(&player[i]) 15 | fmt.Print(" "+player[i]+" score:") 16 | fmt.Scan(&run[i]) 17 | } 18 | for j:=0;j<11;j++{ 19 | if run[j]>max{ 20 | max=run[j] 21 | index=j 22 | }else{ 23 | continue 24 | } 25 | } 26 | fmt.Println("Player with highest score is "+player[index]+" with",run[index],"run") 27 | } -------------------------------------------------------------------------------- /Programming/JavaScript/Algorithm/permutations.js: -------------------------------------------------------------------------------- 1 | // Takes an Array, arr, and returns an Array of all permutations of arr 2 | 3 | const permutations = function(arr) { 4 | let result = []; 5 | 6 | permute(arr, [], result); 7 | 8 | return result; 9 | }; 10 | 11 | const permute = (arr, m = [], result) => { 12 | if (arr.length === 0) { 13 | result.push(m); 14 | 15 | } else { 16 | for (let i = 0; i < arr.length; i++) { 17 | let current = arr.slice(); 18 | let next = current.splice(i, 1); 19 | 20 | permute(current.slice(), m.concat(next), result); 21 | }; 22 | }; 23 | }; 24 | -------------------------------------------------------------------------------- /Programming/JavaScript/Kadanes-Algorithm/KadanesAlgorithm.js: -------------------------------------------------------------------------------- 1 | const kadanesAlgorithm = (nums) => { 2 | let maxCurrent = [nums[0]]; 3 | let maxGlobal = [nums[0]]; 4 | 5 | for (let i = 1; i < nums.length; i++) { 6 | if (nums[i] + maxCurrent[i - 1] > nums[i]) { 7 | maxCurrent[i] = nums[i] + maxCurrent[i - 1]; 8 | } else { 9 | maxCurrent[i] = nums[i]; 10 | }; 11 | 12 | if (maxCurrent[i] > maxGlobal[i - 1]) { 13 | maxGlobal[i] = maxCurrent[i]; 14 | } else { 15 | maxGlobal[i] = maxGlobal[i - 1]; 16 | }; 17 | } 18 | return maxGlobal[maxGlobal.length - 1]; 19 | } 20 | -------------------------------------------------------------------------------- /Programming/Java/ReverseNumber/ReverseNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class ReverseNumber{ 3 | public static void main(String[] args){ 4 | 5 | Scanner sc = new Scanner(System.in); 6 | 7 | // Taking a number in input 8 | 9 | int number = sc.nextInt(); 10 | 11 | int reverse = 0; 12 | 13 | // Reversing the number 14 | 15 | while(number>0){ 16 | int lastDigit = number%10; 17 | reverse = reverse*10 + lastDigit; 18 | number/=10; 19 | } 20 | 21 | System.out.println(reverse); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Programming/Python/Reverse_Integer_python/reverseInt.py: -------------------------------------------------------------------------------- 1 | n=input("Enter a number to reverse: ") 2 | if (int(n)>=2147483648 and int(n)<=2147483647): 3 | s=str(n) 4 | 5 | if s[0]=="-": 6 | s=s[1:] 7 | s1=s[::-1] 8 | for i in range(len(s1)): 9 | if(s1[i]=="0"): 10 | continue 11 | else: 12 | break 13 | print("-" + s1[i:]) 14 | else: 15 | s1=s[::-1] 16 | for i in range(len(s1)): 17 | if(s1[i]=="0"): 18 | continue 19 | else: 20 | break 21 | print(s1[i:]) 22 | 23 |   -------------------------------------------------------------------------------- /Programming/C++/TowerOfHanoi/tower_Of_Hanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | //recursive funtion 4 | void TowerOfHanoi(int num,char A,char B,char C){ 5 | if(num>0){ 6 | TowerOfHanoi(num-1, A, C, B); 7 | cout<<"Move a disk "<>numOfDisk; 16 | 17 | //calling recursive funtion 18 | TowerOfHanoi(numOfDisk,'A','B','C');//A is the source rod , C is destination rod ,B is auxiliary rod 19 | cout< ax^2+bx=c=0 5 | discriminate- d= (b^2-4*a*c) 6 | roots: 7 | alpha=(-b+root(d))/(2*a) 8 | beta=(-b-root(d))/(2*a) 9 | """ 10 | a = float(input('Enter coefficient of x^2: ')) 11 | b = float(input('Enter coefficient of x: ')) 12 | c = float(input('Enter constant: ')) 13 | 14 | # calculate the discriminant 15 | d = (b**2) - (4*a*c) 16 | 17 | # find two solutions 18 | sol1 = (-b-cmath.sqrt(d))/(2*a) 19 | sol2 = (-b+cmath.sqrt(d))/(2*a) 20 | print('The solution are {0} and {1}'.format(sol1,sol2)) 21 | -------------------------------------------------------------------------------- /Programming/Golang/DisplayPrime/DisplayPrimeArrayElementsInput.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/big" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | var arr [20]int64 11 | var input string 12 | 13 | fmt.Println("Enter Integer value") 14 | for i := 0; i < 20; i++ { 15 | 16 | _, _ = fmt.Scan(&input) 17 | 18 | val, err := strconv.ParseInt(input, 10, 64) 19 | if err != nil { 20 | fmt.Println("Not a number") 21 | } else { 22 | arr[i] = val 23 | } 24 | } 25 | fmt.Println("Result") 26 | for i := 0; i < 20; i++ { 27 | if big.NewInt(arr[i]).ProbablyPrime(0) { 28 | fmt.Println(arr[i]) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Programming/JavaScript/SelectionSort/selectionsort.js: -------------------------------------------------------------------------------- 1 | var swap = function (array, firstIndex, secondIndex) { 2 | var temp = array[firstIndex]; 3 | array[firstIndex] = array[secondIndex]; 4 | array[secondIndex] = temp; 5 | }; 6 | var selectionSort = function (array) { 7 | for (var i = 0; i < array.length; i++) { 8 | var min = i; 9 | for (var j = i + 1; j < array.length; j++) { 10 | if (array[j] < array[min]) { 11 | min = j; 12 | } 13 | } 14 | swap(array, i, min); 15 | } 16 | return array; 17 | }; 18 | var array = [3, 2, 10, 1] 19 | console.log(selectionSort(array)); -------------------------------------------------------------------------------- /Programming/C++/LeibnizFormula/LeibnizFormula.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* 6 | Leibniz formula for calculting pi 7 | ------------------------------------ 8 | Sums the reciprocals of consecutive odd numbers, switching signs each time, then multiplies by 4. 9 | Somehow gives you an approximation of pi. 10 | */ 11 | 12 | long double leibniz(int k) { 13 | long double pi = 0.0; 14 | for (int i = 0; i < k; i++) { 15 | pi += (std::pow(-1, i) / (2 * i + 1)); 16 | } 17 | return pi*4.0; 18 | } 19 | 20 | int main() { 21 | std::cout << std::setprecision(32) << leibniz(100000) << std::endl; 22 | } -------------------------------------------------------------------------------- /Programming/Java/Fibonacci/FibonacciSeries.java: -------------------------------------------------------------------------------- 1 | public class FibonacciSeries { 2 | public static void main(String[] args) { 3 | System.out.println(isFibonacci(21)); 4 | System.out.println(isFibonacci(28)); 5 | System.out.println(isFibonacci(2)); 6 | } 7 | public static int isFibonacci(int n){ 8 | int n1=0,n2=1,n3,i; 9 | if (n==1||n==2){ 10 | return 1; 11 | } 12 | for (i=2;i { 2 | for(let index = 0; index <= numbers.length - 2; index += 1) { 3 | for(let j = index +1; j <= numbers.length -1; j +=1){ 4 | if(numbers[index] + numbers[j] === target) { 5 | return [index+1,j+1] 6 | } 7 | } 8 | } 9 | } 10 | 11 | const firstInput = twoSumIndexes([2,7,11,15], 9) 12 | console.log(firstInput) // returns [1,2] 13 | 14 | const secondInput = twoSumIndexes([2,3,4], 6) 15 | console.log(secondInput) // returns [1,3] 16 | 17 | const thridInput = twoSumIndexes([-1,0], -1) 18 | console.log(thridInput) // returns [1,2] -------------------------------------------------------------------------------- /Programming/C/LeibnizFormula/LeibnizFormula.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | Leibniz formula for calculting pi 6 | ------------------------------------ 7 | Sums the reciprocals of consecutive odd numbers, switching signs each time, then multiplies by 4. 8 | Somehow gives you an approximation of pi. 9 | */ 10 | 11 | double leibniz_step(int k) { 12 | return pow(-1, k) / (2 * k + 1); 13 | } 14 | 15 | double leibniz(int k) { 16 | double sum = 0.0; 17 | int i; 18 | 19 | for (i=0; i { 2 | if (left === 0 && right === 0) { 3 | result.push(str); 4 | } 5 | if (left > 0) { 6 | addParanthesisToResult(left - 1, right + 1, str + "(", result); 7 | } 8 | if (right > 0) { 9 | addParanthesisToResult(left, right - 1, str + ")", result); 10 | } 11 | }; 12 | 13 | const generateParenthesis = (n) => { 14 | const result = []; 15 | addParanthesisToResult(n, 0, "", result); 16 | return result; 17 | }; 18 | 19 | 20 | generateParenthesis(3) // ["((()))","(()())","(())()","()(())","()()()"] 21 | generateParenthesis(1) // ["()"] 22 | -------------------------------------------------------------------------------- /Programming/C++/IsPrime/CheckthenumberisPrimeOrNot.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i, num; 7 | bool prime= true; 8 | 9 | cout << "Enter an integer: "; 10 | cin >> num; 11 | 12 | if (num== 0 || num== 1) { 13 | Prime = false; 14 | } 15 | else { 16 | for (i = 2; i <= num / 2; ++i) { 17 | if (num % i == 0) { 18 | Prime = false; 19 | break; 20 | } 21 | } 22 | } 23 | if (Prime) 24 | cout << num << " is a prime number"; 25 | else 26 | cout << num << " is not a prime number"; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Programming/Java/TemperatureConversion/CelciusToFahrenheit.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.text.DecimalFormat; 3 | 4 | /* 5 | The code below will convert Celcius to Fahrenheit 6 | and displays it in the standard output 7 | */ 8 | 9 | public class CelciusToFahrenheit{ 10 | public static void main(String[] args) { 11 | 12 | Scanner input = new Scanner(System.in); 13 | System.out.print("Enter temperature in Celcius: "); 14 | Double temp = input.nextDouble(); 15 | DecimalFormat df = new DecimalFormat("#0.##"); // 2 decimal format precision 16 | System.out.println(temp + "°C = " + df.format((temp * 1.8) + 32) + "°F"); 17 | } 18 | } -------------------------------------------------------------------------------- /Programming/Python/HighScorer/DisplayRunsScored.py: -------------------------------------------------------------------------------- 1 | # Contributed by @mcole18 2 | # assumes input is of the form 3 | # player_name2 : score2, ..., player_nameN : scoreN 4 | # ex: 5 | # Stacie : 22, Tom : 2, Arnold : 11, ..., Marnie : 5 6 | 7 | string = input() 8 | player_scores = dict((name.strip(), score.strip()) 9 | for name, score in (player_tuple.split(':') 10 | for player_tuple in string.split(', '))) 11 | 12 | top_scorer = next(iter(player_scores)) 13 | for player in player_scores: 14 | if int(player_scores[top_scorer]) < int(player_scores[player]): 15 | top_scorer = player 16 | 17 | print('The top scorer is: ' + top_scorer + ' with ' + player_scores[top_scorer] + ' runs.') 18 | -------------------------------------------------------------------------------- /Programming/Python/RomanToInteger/RomanToInteger.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def romanToInt(self, s): 3 | """ 4 | :type s: str 5 | :rtype: int 6 | """ 7 | roman = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000,'IV':4,'IX':9,'XL':40,'XC':90,'CD':400,'CM':900} 8 | i = 0 9 | num = 0 10 | while i < len(s): 11 | if i+1 0; i = i / 10 { 33 | numSlice = append(numSlice, i%10) 34 | } 35 | 36 | return numSlice 37 | } 38 | -------------------------------------------------------------------------------- /Programming/C#/SwappingTwoNumbers/SwappingTwoNumbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | double first, second, temp; 4 | printf("Enter first number: "); 5 | scanf("%lf", &first); 6 | printf("Enter second number: "); 7 | scanf("%lf", &second); 8 | 9 | // Value of first is assigned to temp 10 | temp = first; 11 | 12 | // Value of second is assigned to first 13 | first = second; 14 | 15 | // Value of temp (initial value of first) is assigned to second 16 | second = temp; 17 | 18 | printf("\nAfter swapping, firstNumber = %.2lf\n", first); 19 | printf("After swapping, secondNumber = %.2lf", second); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Programming/Java/DistanceBetweenBusStops/DistanceBetweenBusStops.java: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/distance-between-bus-stops/ 2 | 3 | class Solution { 4 | public int distanceBetweenBusStops(int[] distance, int start, int destination) { 5 | int clockwise = 0, anticlockwise = 0; 6 | int i = start; 7 | 8 | while(i != destination) { 9 | clockwise += distance[i]; 10 | i = (i + 1)%distance.length; 11 | } 12 | 13 | while(i != start) { 14 | anticlockwise += distance[i]; 15 | i = (i + 1)%distance.length; 16 | } 17 | 18 | return Math.min(anticlockwise, clockwise); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Programming/Java/Container With Most Water/containerWithMostWater.txt: -------------------------------------------------------------------------------- 1 | Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). 2 | n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). 3 | Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. 4 | 5 | Notice that you may not slant the container. 6 | 7 | Example 1: 8 | Input: height = [1,8,6,2,5,4,8,3,7] 9 | Output: 49 10 | 11 | Example 2: 12 | Input: height = [1,1] 13 | Output: 1 14 | 15 | 16 | Example 3: 17 | Input: height = [4,3,2,1,4] 18 | Output: 16 19 | 20 | Example 4: 21 | Input: height = [1,2,1] 22 | Output: 2 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /Programming/C++/BalanceStrings/BalanceStrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int balancedStringSplit(string s) 7 | { 8 | int cr = 0, cl = 0, c = 0; 9 | for (int i = 0; i < s.length(); i++) 10 | { 11 | if (s[i] == 'R') 12 | { 13 | cr++; 14 | } 15 | else if (s[i] == 'L') 16 | { 17 | cl++; 18 | } 19 | if (cr == cl) 20 | { 21 | c++; 22 | cr = 0; 23 | cl = 0; 24 | } 25 | } 26 | return c; 27 | } 28 | 29 | int main() 30 | { 31 | string s; 32 | cin >> s; 33 | 34 | cout << balancedStringSplit(s); 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Programming/C++/WordsStartingWithVowels/CountTheWordsStartingWithVowels.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void main() 6 | { 7 | int vc=0; 8 | char sen[25], ch; 9 | 10 | cout<< "\n Type A Sentance:"; 11 | cin.getline(sen,25); 12 | 13 | for(int i =0; sen[i]!='\0'; i++) 14 | { 15 | if(sen[i]==' ') 16 | { 17 | while(sen[i] = = ' ') /* remove multiple space */ 18 | i++; 19 | 20 | ch = toupper(sen[i]); 21 | 22 | switch(ch) 23 | { 24 | case 'A': 25 | case 'E': 26 | case 'O': 27 | case 'I': 28 | case 'U': 29 | vc++; 30 | } 31 | } 32 | } 33 | cout<<"\n The total number of words starting with a vowel is : "<< vc; 34 | 35 | getch(); 36 | } -------------------------------------------------------------------------------- /Programming/Java/PalindromeOrNot/PalindromeCheck.java: -------------------------------------------------------------------------------- 1 | package com.raven7; 2 | 3 | import java.util.Scanner; 4 | 5 | class PalindromeCheck{ 6 | public static void main(String args[]) 7 | { 8 | String original, reverse = ""; // Objects of String class 9 | Scanner in = new Scanner(System.in); 10 | System.out.println("Enter the number: "); 11 | original = in.nextLine(); 12 | int length = original.length(); 13 | for ( int i = length - 1; i >= 0; i-- ) 14 | reverse = reverse + original.charAt(i); 15 | if (original.equals(reverse)) 16 | System.out.println("True"); 17 | else 18 | System.out.println("False"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Programming/Python/GradingStudents/gradingStudents.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | def gradingStudents(grades): 5 | for i in range(len(grades)): 6 | if(grades[i]>37): 7 | if((grades[i]%5)!=0): 8 | if(5-(grades[i]%5)<3): 9 | grades[i]+=5-(grades[i]%5) 10 | return (grades) 11 | 12 | if __name__ == '__main__': 13 | f = open(os.environ['OUTPUT_PATH'], 'w') 14 | 15 | n = int(input()) 16 | 17 | grades = [] 18 | 19 | for _ in range(n): 20 | grades_item = int(input()) 21 | grades.append(grades_item) 22 | 23 | result = gradingStudents(grades) 24 | 25 | f.write('\n'.join(map(str, result))) 26 | f.write('\n') 27 | 28 | f.close() 29 | -------------------------------------------------------------------------------- /Programming/C++/HighestScorer/HighScorer2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int score[11]={0}; 8 | string name[11]={""}; 9 | cout<<"Enter the details 11 players"<>name[i]; 15 | cout<<"Enter the score of player "<>score[i]; 17 | if(max 2 | 3 | using namespace std; 4 | 5 | int checkPrime(int n) { 6 | bool isPrime = true; 7 | 8 | for(int i = 2; i <= n/2; i++) { 9 | if (n%i == 0) 10 | { 11 | isPrime = false; 12 | break; 13 | } 14 | } 15 | return isPrime; 16 | } 17 | 18 | int main() { 19 | bool isPrime; 20 | int input; 21 | cout<<"Enter a number:"; 22 | cin>>input; 23 | if(input == 1) 24 | cout<<"neither prime nor composite"; 25 | if(input <0) 26 | cout<<"enter positive number" 27 | for(int n = 2; n < input; n++) 28 | { 29 | if(checkPrime(n) == true) 30 | cout< 2 | using namespace std; 3 | 4 | void addingpar(vector &v, string str, int n, int m) { 5 | if (n == 0 && m == 0) { 6 | v.push_back(str); 7 | return; 8 | } 9 | if (m > 0) { addingpar(v, str + ")", n, m - 1); } 10 | if (n > 0) { addingpar(v, str + "(", n - 1, m + 1); } 11 | } 12 | 13 | vector generateParenthesis(int n) { 14 | vector res; 15 | addingpar(res, "", n, 0); 16 | return res; 17 | } 18 | 19 | int main() 20 | { 21 | int n; 22 | cin>>n; 23 | 24 | vector v = generateParenthesis(n); 25 | 26 | for(int i=0;i { 2 | let result = 0, 3 | startIndex = 0, 4 | endIndex = heights.length - 1; 5 | while (startIndex < endIndex) { 6 | result = Math.max(result, Math.min(heights[startIndex], heights[endIndex]) * (endIndex - startIndex)); 7 | heights[startIndex] <= heights[endIndex] ? startIndex++ : endIndex--; 8 | } 9 | return result; 10 | }; 11 | 12 | containerWithMostWater([1, 8, 6, 2, 5, 4, 8, 3, 7]); // returns 49 13 | containerWithMostWater([1,1]) // returns 1 14 | containerWithMostWater([4,3,2,1,4]) // returns 16 15 | containerWithMostWater([1,2,1]) // returns 2 16 | -------------------------------------------------------------------------------- /Programming/C++/SinglyLinkedList/Linkedlist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct Node { 4 | int data; 5 | struct Node *next; 6 | }; 7 | struct Node* head = NULL; 8 | void insert(int new_data) { 9 | struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); 10 | new_node->data = new_data; 11 | new_node->next = head; 12 | head = new_node; 13 | } 14 | void display() { 15 | struct Node* ptr; 16 | ptr = head; 17 | while (ptr != NULL) { 18 | cout<< ptr->data <<" "; 19 | ptr = ptr->next; 20 | } 21 | } 22 | int main() { 23 | insert(3); 24 | insert(1); 25 | insert(7); 26 | insert(2); 27 | insert(9); 28 | cout<<"The linked list is: "; 29 | display(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Programming/C++/Integer_to_Roman/INTEGER_TO_ROMAN.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to convert decimal number to 2 | // roman numerals 3 | #include 4 | using namespace std; 5 | 6 | // Function to convert decimal to Roman Numerals 7 | int printRoman(int number) 8 | { 9 | int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000}; 10 | string sym[] = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"}; 11 | int i=12; 12 | while(number>0) 13 | { 14 | int div = number/num[i]; 15 | number = number%num[i]; 16 | while(div--) 17 | { 18 | cout<> n; 29 | // enter your number to be converted . 30 | 31 | printRoman(n); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Programming/C++/HighestScorer/HighestScorer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int highestScore=0,players=11,currentScore; 8 | string highestScorerName,currentScorerName; 9 | 10 | for(int i=0;i>currentScorerName; 13 | 14 | cout<<"Score of "<>currentScore; 16 | 17 | if(currentScore>highestScore){ 18 | highestScore=currentScore; 19 | highestScorerName=currentScorerName; 20 | } 21 | } 22 | 23 | cout<<"Highest scorer is "< 2 | #include 3 | int main() 4 | { 5 | int nums[100],i,j,size,target,sum=0; 6 | printf("Enter the size of an array\n"); 7 | scanf("%d",&size); 8 | printf("Enter an array elements\n"); 9 | for(i=0;i 2 | #include 3 | 4 | //defining the function 5 | void int_to_roman(num){ 6 | //creating lists for the conversion 7 | int nums[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; 8 | char romans[] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; 9 | int i = 0; 10 | //while loop fpr printing the roman 11 | while(num){ 12 | while(num/nums[i]){ 13 | printf("%s",romans[i]); 14 | num -= nums[i]; 15 | } 16 | i++; 17 | } 18 | } 19 | 20 | //driver code 21 | int main(){ 22 | int n; 23 | printf("Enter the number for converting into roman: "); 24 | scanf("%d",&n); 25 | int_to_roman(n); // calling the function 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Programming/Golang/Roman_to_Integer/roman_to_integer.go: -------------------------------------------------------------------------------- 1 | package main 2 | import ( 3 | "fmt" 4 | ) 5 | 6 | func get_integer_from_roman(roman string) int { 7 | ma := map[string]int{ 8 | "I": 1, 9 | "V": 5, 10 | "X": 10, 11 | "L": 50, 12 | "C": 100, 13 | "D": 500, 14 | "M": 1000, 15 | } 16 | var prev, curr, ans int 17 | for _, char := range roman { 18 | curr = ma[string(char)] 19 | if curr > prev { 20 | ans += curr - 2*prev 21 | } else { 22 | ans += curr 23 | } 24 | prev = curr 25 | } 26 | return ans 27 | } 28 | 29 | func main() { 30 | var roman string 31 | fmt.Println("Enter the roman number!\n") 32 | fmt.Scan(&roman) 33 | var integer int 34 | integer = get_integer_from_roman(roman) 35 | fmt.Println(roman, "-->", integer) 36 | } -------------------------------------------------------------------------------- /Programming/Java/TemperatureConversion/ConvertCelsiusIntoFahrenheit.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.Scanner; 3 | 4 | public class ConvertCelsiusIntoFahrenheit { 5 | public static void main(String[] args) { 6 | Scanner obj = new Scanner(System.in); 7 | System.out.println("Enter a sentence"); 8 | Scanner in = new Scanner(System.in); 9 | 10 | /* Input temperature in Celsius from user */ 11 | System.out.print("Enter temperature in Celsius: "); 12 | float C = in.nextFloat(); 13 | 14 | /* Convert Celsius to Fahrenheit */ 15 | float F = C * (9f / 5) + 32; 16 | 17 | /* Print result */ 18 | System.out.println(C + " degree Celsius is equal to " + F +" degree Fahrenheit."); 19 | } 20 | } -------------------------------------------------------------------------------- /Programming/Java/EvenOrOdd/EvenOrOdd.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class EvenOrOdd 4 | { 5 | public static void main(String[] args) 6 | { 7 | Scanner scan = new Scanner(System.in); 8 | System.out.println("Enter your favorite real number."); 9 | int num = scan.nextInt(); 10 | System.out.println(); 11 | condition(num); 12 | 13 | if(num % 2 == 0) 14 | System.out.println(num + " Is an even number."); 15 | else 16 | System.out.println(num + " Is an odd number."); 17 | } 18 | 19 | static void condition(int value) 20 | { 21 | if(value <= 0) { 22 | System.out.println("That number isn't even or odd. Try again."); 23 | main(null); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Programming/Python/LengthOfLongestSubstring/length_of_longest_substring_without_repeating_characters.py: -------------------------------------------------------------------------------- 1 | #contributed by @nikhil05-code 2 | #Here we are finding the length of the longest substring without repeating characters. 3 | def lengthOfLongestSubstring(self, s): 4 | 5 | if len(s) == 0: return 0 6 | 7 | start = 0 8 | maxLength = 0 9 | 10 | usedChars = {} 11 | 12 | for i in range(len(s)): 13 | if s[i] in usedChars and start <= usedChars[s[i]]: 14 | start = usedChars[s[i]] + 1 15 | else: 16 | maxLength = max(maxLength, i - start + 1) 17 | usedChars[s[i]] = i 18 | 19 | 20 | return maxLength 21 | #print(lengthOfLongestSubstring("abracadabra")) 22 | #Output:4 23 | #Explanation: The answer is "brac", with the length of 4. 24 | -------------------------------------------------------------------------------- /Programming/C++/LuhnAlgorithm/luhn's_algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool checkLuhn(const string& cardNo) 5 | { 6 | int nDigits = cardNo.length(); 7 | 8 | int nSum = 0, isSecond = false; 9 | for (int i = nDigits - 1; i >= 0; i--) { 10 | 11 | int d = cardNo[i] - '0'; 12 | 13 | if (isSecond == true) 14 | d = d * 2; 15 | 16 | nSum += d / 10; 17 | nSum += d % 10; 18 | 19 | isSecond = !isSecond; 20 | } 21 | return (nSum % 10 == 0); 22 | } 23 | 24 | int main() 25 | { 26 | string cardNo = "79927398713"; 27 | if (checkLuhn(cardNo)) 28 | printf("This is a valid card"); 29 | else 30 | printf("This is not a valid card"); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Programming/C++/TopologicalSorting/TopologicalSorting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | vector adj[11]; 4 | int vis[11]; 5 | void topo(int src,stack &s) 6 | { 7 | vis[src]=1; 8 | for(int a:adj[src]) 9 | { 10 | if(vis[a]==0) 11 | topo(a,s); 12 | } 13 | s.push(src); 14 | } 15 | int main() 16 | { 17 | int n,m; 18 | cin>>n>>m; 19 | for(int i=0;i<=n;i++) 20 | adj[i].clear(); 21 | memset(vis,0,sizeof(vis)); 22 | int a,b; 23 | for(int i=0;i>a>>b; 26 | adj[a].push_back(b); 27 | } 28 | stack s; 29 | for(int i=1;i<=n;i++) 30 | sort(adj[i].rbegin(),adj[i].rend()); 31 | for(int i=n;i>=1;i--) 32 | { 33 | if(vis[i]==0) 34 | topo(i,s); 35 | } 36 | while(!s.empty()) 37 | { 38 | cout<= target: 7 | r = mid 8 | else: 9 | l = mid + 1 10 | return l if target <= nums[l] else l + 1 11 | 12 | # This algorithm will give us O(n^2logn) time complexity. 13 | def triangleNumber(self, nums): 14 | nums.sort() 15 | result = 0 16 | for i in range(len(nums) - 2): 17 | for j in range(i + 1, len(nums) - 1): 18 | k = self.binarySearch(nums, j + 1, len(nums) - 1, nums[i] + nums[j]) 19 | result += (k - 1) - j 20 | return result 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Programming/C#/Combination Sum/readme.md: -------------------------------------------------------------------------------- 1 | # 39. Combination Sum 2 | 3 | Given a **set** of candidate numbers (`candidates`) (**without duplicates**) and a target number (`target`), find all unique combinations in `candidates` where the candidate numbers sums to `target`. 4 | 5 | The same repeated number may be chosen from candidates unlimited number of times. 6 | 7 | **Note**: 8 | 9 | - All numbers (including `target`) will be positive integers. 10 | - The solution set must not contain duplicate combinations. 11 | 12 | ### Example 1: 13 | ``` 14 | Input: candidates = [2,3,6,7], target = 7, 15 | A solution set is: 16 | [ 17 | [7], 18 | [2,2,3] 19 | ] 20 | ``` 21 | 22 | ### Example 2: 23 | ``` 24 | Input: candidates = [2,3,5], target = 8, 25 | A solution set is: 26 | [ 27 | [2,2,2,2], 28 | [2,3,3], 29 | [3,5] 30 | ] 31 | ``` -------------------------------------------------------------------------------- /Programming/JavaScript/CombinationSum/combinationSum.js: -------------------------------------------------------------------------------- 1 | const combinationSum = (candidates, target) => { 2 | const result = []; 3 | const permute = (arr = [], sum = 0, idx = 0) => { 4 | if (sum > target) return; 5 | if (sum === target) result.push(arr); 6 | 7 | for (let i = idx; i < candidates.length; i++) { 8 | permute([...arr, candidates[i]], sum + candidates[i], i); 9 | } 10 | }; 11 | permute(); 12 | return result; 13 | }; 14 | 15 | combinationSum([2, 3, 6, 7], 7); // returns [ [ 2, 2, 3 ], [ 7 ] ] 16 | combinationSum([2, 3, 5], 8); // returns [ [ 2, 2, 2, 2 ], [ 2, 3, 3 ], [ 3, 5 ] ] 17 | combinationSum([2], 1); // returns [ ] 18 | combinationSum([1], 1); // returns [ [ 1 ] ] 19 | combinationSum([1], 2); // returns [ [ 1, 1 ] ] 20 | -------------------------------------------------------------------------------- /Programming/Python/Roman_to_Integer/roman_to_integer.py: -------------------------------------------------------------------------------- 1 | def get_integer_from_roman(roman): 2 | dictionary = { 3 | 'I': 1, 4 | 'V': 5, 5 | 'X': 10, 6 | 'L': 50, 7 | 'C': 100, 8 | 'D': 500, 9 | 'M': 1000 10 | } 11 | prev, curr, ans = 0, 0, 0 12 | for char in roman: 13 | curr = dictionary.get(char) 14 | if not curr: 15 | return "Does not exist!" 16 | ans += curr - 2*prev if curr > prev else curr 17 | prev = curr 18 | return ans 19 | 20 | 21 | def main(): 22 | roman = input('Enter the roman number!\n') 23 | integer = get_integer_from_roman(roman) 24 | if integer == "Does not exist!": 25 | print(integer) 26 | print('Please give a correct number or in the range of 1 to 3999') 27 | return 28 | print(roman, '-->', integer) 29 | 30 | if __name__ == '__main__': 31 | main() -------------------------------------------------------------------------------- /Programming/C++/Generate Parenthesis/parenthesesCombinations.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | # define MAX_COUNT 100 4 | void printParenthesesPairs(int pos, int n, int open, int close){ 5 | static char str[MAX_COUNT]; 6 | if(close == n) { 7 | cout< close) { 12 | str[pos] = ')'; 13 | printParenthesesPairs(pos+1, n, open, close+1); 14 | } 15 | if(open < n) { 16 | str[pos] = '('; 17 | printParenthesesPairs(pos+1, n, open+1, close); 18 | } 19 | } 20 | } 21 | int main() { 22 | int n; 23 | 24 | cout<<"Enter a number for Parenthesis Combinations: "; 25 | cin>>n; 26 | if(n > 0) 27 | printParenthesesPairs(0, n, 0, 0); 28 | getchar(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Programming/Java/CheckPrime/CheckPrime.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class CheckPrime{ 3 | public static void main(String[] args) { 4 | 5 | try(Scanner sc = new Scanner(System.in)){ 6 | System.out.println("enter a number"); 7 | int n = sc.nextInt(); 8 | 9 | 10 | boolean isprime = true; 11 | for(int i=2; i*i<=n;i++){ 12 | if(n%i==0){ 13 | isprime = false; 14 | break; 15 | } 16 | } 17 | if(n<2){ 18 | isprime = false; 19 | } 20 | if(isprime){ 21 | System.out.print(n+" is not a Prime Number"); 22 | }else{ 23 | System.out.print(n+" is a Prime Number"); 24 | } 25 | }catch(Exception ex){ 26 | ex.printStackTrace(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Programming/C++/WordsStartingWithVowels/WordsStartWithVowels2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | 5 | int count = 0; 6 | string str; 7 | getline(cin,str); 8 | 9 | //to convert the string to lowercase 10 | transform(str.begin(), str.end(), str.begin(), ::tolower); 11 | 12 | // Checks whether the 1st character is a vowel 13 | if(str[0]=='a' || str[0]=='e' || str[0]== 'i' || str[0]== 'o' || str[0]== 'u') { 14 | //Increments the vowel counter 15 | count++; 16 | } 17 | 18 | for(int i=1;i animals = new LinkedList(); 11 | // animals.add("fox"); 12 | // animals.add("cat"); 13 | // animals.add("dog"); 14 | // animals.add("rabbit"); 15 | //// animals.add("tiger"); 16 | // 17 | // Iterator it = animals.iterator(); 18 | // while (it.hasNext()) { 19 | // Collections.sort(animals); //sorting array 20 | // String value = it.next(); 21 | // System.out.println(value); 22 | // } 23 | // } 24 | //}class iterator { 25 | // 26 | //} 27 | -------------------------------------------------------------------------------- /Programming/JavaScript/Merge-Sort/mergeSort.js: -------------------------------------------------------------------------------- 1 | const merge = (left, right) => { 2 | const temp = [] 3 | let i = 0, j = 0 4 | while (i < left.length && j < right.length) { 5 | if (left[i] < right[j]) temp.push(left[i++]) 6 | else temp.push(right[j++]) 7 | } 8 | for (let k=i; k < left.length; k++) { 9 | temp.push(left[k]) 10 | } 11 | for (let k=j; k < right.length; k++) { 12 | temp.push(right[k]) 13 | } 14 | return temp; 15 | } 16 | 17 | const mergeSort = (arr) => { 18 | if (arr.length > 1) { 19 | const mid = Math.floor(arr.length / 2) 20 | const left = arr.slice(0, mid) 21 | const right = arr.slice(mid) 22 | return merge(mergeSort(left), mergeSort(right)) 23 | } 24 | return arr; 25 | } 26 | 27 | const test = [1, 0, 8, 4, 3, 2, 7, 5, 6] 28 | console.log(mergeSort(test)) 29 | -------------------------------------------------------------------------------- /Programming/C++/PrimeGame/Prime_Game.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Prime Game 5 | Given two integers x and y(x>y). The only operation you can perform is, choose any Prime integer m 6 | and subtract it any number of times from x. The task is to determine whether it is possible to make x 7 | equal to y. 8 | 9 | Input format 10 | The first line and the only line of input contains two integers x and y separated by space. 11 | 12 | Output format 13 | Output "YES" (without quotes, in capital) if it is possible to make x equal to y, otherwise output "NO"(without quotes, in capital). 14 | 15 | Constraints 16 | 1<=x,y<=10^18 17 | 18 | */ 19 | 20 | #include 21 | using namespace std; 22 | #define ll long long 23 | int main() 24 | { 25 | ll x,y; 26 | cin>>x>>y; 27 | if(abs(x-y)==1){ 28 | cout<<"NO"< 2 | 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | std::ios_base::sync_with_stdio(false); 9 | 10 | int Lcase = 0, Ucase = 0, digit = 0, sp = 0; 11 | 12 | string s; 13 | cout << "Enter Your Password: " ; 14 | cin >> s; 15 | 16 | for (int i = 0; i < s.length(); ++i) { 17 | 18 | if (islower(s[i])) { 19 | Lcase += 1; 20 | } 21 | if (isupper(s[i])) { 22 | Ucase += 1; 23 | 24 | } 25 | if (isdigit(s[i])) { 26 | digit += 1; 27 | } 28 | if (!isalpha(s[i]) && !isdigit(s[i])) { 29 | sp += 1; 30 | } 31 | } 32 | 33 | if ((Lcase && Ucase && digit && sp >= 1) && (s.length() >= 8)) { 34 | cout << "TRUE" << endl; 35 | } else { 36 | cout << "FALSE" << endl; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Programming/Golang/WordsStartWithVowels/WordsStartWithVowels.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* Problem: Given an string, count the number of words beginning with vowels. 4 | Eg: 5 | Sample Input: "Apple and banana are healthy fruits." 6 | Sample Output: The input sentence contains 3 words that begin with vowels. 7 | */ 8 | 9 | import ( 10 | "fmt" 11 | "strings" 12 | ) 13 | 14 | //counts number of words beginning with vowels 15 | func countVowelBeginWords(s string) int { 16 | count := 0 17 | 18 | words := strings.Fields(s) 19 | for i := range words { 20 | temp := string(words[i][0]) 21 | switch strings.ToUpper(temp) { 22 | case "A", "E", "I", "O", "U": 23 | count++ 24 | } 25 | } 26 | return count 27 | } 28 | 29 | func main() { 30 | s := "Apple and banana are healthy fruits." 31 | ans := countVowelBeginWords(s) 32 | fmt.Printf("The input sentence contains %v words that begin with vowels.\n", ans) 33 | } 34 | -------------------------------------------------------------------------------- /Programming/Java/FizzBuzz/FizzBuzz.java: -------------------------------------------------------------------------------- 1 | public class FizzBuzz 2 | { 3 | // algorithm replaces multiples of 3 with 'Fizz' 4 | // multiples of 5 are replaced with 'Buzz' 5 | // if a number is a multiple of both it will print 'FizzBuzz' 6 | public static void main(String[] args) 7 | { 8 | for (int i = 1; i < 101; i++)// loops through body 100 times starting at 1 9 | { 10 | if(i % 5 == 0)// % or mod checks for remainders after division 11 | { 12 | if(i % 3 == 0) 13 | System.out.println("FizzBuzz"); 14 | else 15 | System.out.println("Buzz"); 16 | } 17 | else 18 | { 19 | if(i % 3 == 0) 20 | System.out.println("Fizz"); 21 | else 22 | System.out.println(i); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Programming/C++/CombinationSum/CombinationSum.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector> vec; 5 | 6 | void helper(vector &nums, int key, vector ¤tItems, int idx = 0) 7 | { 8 | if (key == 0) 9 | { 10 | vec.push_back(currentItems); 11 | return; 12 | } 13 | 14 | if (key < 0) 15 | return; 16 | if (idx < nums.size()) 17 | { 18 | currentItems.push_back(nums[idx]); 19 | helper(nums, key - nums[idx], currentItems, idx); // if not same element then idx+1 20 | currentItems.pop_back(); 21 | helper(nums, key, currentItems, idx + 1); 22 | } 23 | } 24 | 25 | vector> combinationSum(vector &candidates, int target) 26 | { 27 | vector res; 28 | helper(candidates, target, res); 29 | 30 | return vec; 31 | } 32 | }; -------------------------------------------------------------------------------- /Programming/C/BinarySearch/Binary_Search.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int BinarySearch(int arr[], int size, int element){ 4 | int low, mid, high; 5 | low = 0; 6 | high = arr[size-1]; 7 | 8 | // Start Searching : until low and high converges 9 | while(low<=high) 10 | { 11 | mid = (low + high)/2; 12 | if(arr[mid] == element) 13 | { 14 | return mid; 15 | } 16 | if(arr[mid] == element) 17 | { 18 | low = mid+1; 19 | } 20 | else 21 | { 22 | high = mid-1; 23 | } 24 | } 25 | 26 | int main(){ 27 | int arr[] ={1,3,4,6,34,6,43,66,32}; 28 | int size = sizeof(arr)/sizeof(int); 29 | int element = 6; 30 | int SearchIndex = BinarySearch(arr, size, element); 31 | printf("The element %d was found at index %d \n",element, SearchIndex); 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Programming/JavaScript/BFS/02.Queue.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = class Queue { 4 | constructor(mySize) { 5 | this.items = []; 6 | this.size = mySize; 7 | this.front = 0; 8 | this.back = -1; 9 | } 10 | 11 | isFull() { 12 | return this.items.length >= this.size; 13 | } 14 | 15 | isEmpty() { 16 | return this.items.length == 0; 17 | } 18 | 19 | getFront() { 20 | if (this.items.length != 0) { 21 | return this.items[0]; 22 | } else { 23 | console.log('No elements in the queue'); 24 | } 25 | } 26 | 27 | enqueue(element) { 28 | if (this.items.length >= this.size) { 29 | console.log('Queue is full'); 30 | } else { 31 | this.items.push(element); 32 | } 33 | } 34 | 35 | dequeue() { 36 | if (this.items.length == 0) { 37 | console.log('No elements'); 38 | } else { 39 | return this.items.shift(); 40 | } 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /Programming/C++/PossibleSum/Possible_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define pb push_back 4 | #define MAXN (int)1e5+100 5 | 6 | using namespace std; 7 | 8 | int n, s, x[30]; 9 | vectorans; 10 | bool rec(int pos, int sum) 11 | { 12 | if(pos==n) 13 | { 14 | if(sum==s)return true; 15 | return false; 16 | } 17 | 18 | if(rec(pos+1, sum+x[pos])){ans.pb('+');return true;} 19 | if(rec(pos+1, sum-x[pos])){ans.pb('-');return true;} 20 | } 21 | 22 | int main() 23 | { 24 | cin>>n>>s; 25 | for(int i=0; i>x[i]; 28 | } 29 | 30 | rec(1, x[0]); 31 | reverse(ans.begin(), ans.end()); 32 | if(!ans.empty()) 33 | { 34 | cout< list = new ArrayList<>(); 10 | for (int i = 1; i <= t; i++) { 11 | list.add(sc.next().trim()); 12 | } 13 | System.out.println(list); 14 | int count = 0; 15 | for(int i=0;i 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n; 8 | cin>>n; 9 | //size of array 10 | 11 | int arr[n]; 12 | //Take input of a sorted array 13 | 14 | for(int i=0;i>arr[i]; 16 | 17 | int cnt=1; 18 | // bcz arr[0] is always in output array 19 | 20 | for(int i=1;i pq = new PriorityQueue<>(); 15 | for (int i =0;i< arr.length;i++){ 16 | if (i pq.peek()){ 21 | pq.remove(); 22 | pq.add(arr[i]); 23 | } 24 | } 25 | } 26 | 27 | while (pq.size()>0){ 28 | System.out.println(pq.remove()); 29 | } 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Programming/C#/ReverseInteger/ReverseInteger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace ReverseInteger 5 | { 6 | public class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | Console.WriteLine("Enter an integer number:"); 11 | var number = Console.ReadLine(); 12 | Console.WriteLine($"Reverse number is: {ReverseInteger(number)}"); 13 | 14 | Console.ReadLine(); 15 | } 16 | 17 | public static string ReverseInteger(string stringNumberWithSign) 18 | { 19 | var sb = new StringBuilder(); 20 | var charArray = stringNumberWithSign.Replace("-", string.Empty).ToCharArray(); 21 | Array.Reverse(charArray); 22 | sb.Append(charArray); 23 | if(stringNumberWithSign.StartsWith('-')) 24 | { 25 | sb.Insert(0, '-'); 26 | } 27 | return sb.ToString(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Programming/Python/LetterCombinationsOfAPhoneNumber/LetterCombinationsOfAPhoneNumber.py: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // LetterCombinationsOfAPhoneNumber.c 4 | // 5 | // 6 | // Created by Arihant Thriwe on 02/10/21. 7 | // 8 | 9 | class Solution(object): 10 | def letterCombinations(self, digits): 11 | dmap = {'2': 'abc', 12 | '3': 'def', 13 | '4': 'ghi', 14 | '5': 'jkl', 15 | '6': 'mno', 16 | '7': 'pqrs', 17 | '8': 'tuv', 18 | '9': 'wxyz', 19 | } 20 | 21 | # DFS 22 | result = [] 23 | ls = len(digits) 24 | if ls == 0: 25 | return result 26 | current = digits[0] 27 | posfix = self.letterCombinations(digits[1:]) 28 | for t in dmap[current]: 29 | if len(posfix) > 0: 30 | for p in posfix: 31 | temp = t + p 32 | result.append(temp) 33 | else: 34 | result.append(t) 35 | return result 36 | -------------------------------------------------------------------------------- /Programming/C#/CheckForPalindrome/Palindrome.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Palindrome 4 | { 5 | class Palindrome 6 | { 7 | static void Main(string[] args) 8 | { 9 | int number, r, sum = 0, temp; 10 | 11 | Console.Write("Enter the number: "); 12 | number = int.Parse(Console.ReadLine()); 13 | temp = number; 14 | Console.WriteLine(); 15 | 16 | while (number > 0) 17 | { 18 | r = number % 10; 19 | sum = (sum * 10) + r; 20 | number = number / 10; 21 | } 22 | 23 | if (temp == sum) 24 | Console.Write("Number is a palindrome."); 25 | else 26 | Console.WriteLine("Number is not a palindrome"); 27 | 28 | Console.WriteLine(); 29 | Console.WriteLine(); 30 | Console.WriteLine("Press enter to close..."); 31 | Console.ReadLine(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Programming/C#/Pallindrome/Pallindrome.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Pallindrome 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int num, rem, sum = 0, temp; 10 | Console.WriteLine("\n >>>>Enter a number to discover if Number is Palindrome or not <<<< "); 11 | Console.Write("\n Enter a number: "); 12 | num = Convert.ToInt32(Console.ReadLine()); 13 | temp = num; 14 | while (num > 0) 15 | { 16 | rem = num % 10; 17 | num = num / 10; 18 | sum = sum * 10 + rem; 19 | } 20 | if (temp == sum) 21 | { 22 | Console.WriteLine("\n Number is Palindrome \n\n"); 23 | } 24 | else 25 | { 26 | Console.WriteLine("\n Number is not a palindrome \n\n"); 27 | } 28 | Console.ReadLine(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Programming/Java/NumberSquare/NumberSquare.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package numbersquare; 7 | 8 | import java.util.Scanner; 9 | 10 | /** 11 | * 12 | * @author Master Irfak 13 | */ 14 | public class NumberSquare { 15 | 16 | public static void main(String[] args) { 17 | Scanner input = new Scanner(System.in); 18 | System.out.print("Input Your Number : "); 19 | int number = input.nextInt(); 20 | for (int i = 0; i < number; i++) { 21 | for (int j = 0; j < number; j++) { 22 | if (i == 0 || i == (number - 1) || j == 0 || j == (number - 1)) { 23 | System.out.print(number); 24 | } else { 25 | System.out.print(" "); 26 | } 27 | } 28 | System.out.println(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Programming/Python/CombinationSum/combinationSum.py: -------------------------------------------------------------------------------- 1 | def combinationSum(candidates, target): 2 | candidates.sort() 3 | def dfs(start,current, sum): 4 | if sum == target: 5 | result.append([]+current) 6 | return 7 | for i in range(start,len(candidates)): 8 | if(sum+candidates[i] > target): 9 | break 10 | current.append(candidates[i]) 11 | dfs(i,current,sum+candidates[i]) 12 | current.pop() 13 | 14 | result = [] 15 | dfs(0,[],0) 16 | return result 17 | 18 | if __name__ == '__main__': 19 | import sys 20 | 21 | candidates = [2,3,6,7]; target = 7 22 | output = combinationSum(candidates, target) 23 | print(output) 24 | #Output: [[2,2,3],[7]] 25 | 26 | candidates = [2,3,5]; target = 8 27 | output = combinationSum(candidates, target) 28 | print(output) 29 | #Output: [[2,2,2,2],[2,3,3],[3,5]] 30 | 31 | -------------------------------------------------------------------------------- /Programming/C#/PhoneLetterCombo/README.md: -------------------------------------------------------------------------------- 1 | # 22. Letter Combinations of a Phone Number [C#-Solution required] 2 | 3 | Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. 4 | 5 | A mapping of digit to letters (just like on a telephone) is given below. Note that 1 does not map to any letters. 6 | 7 | 2. "abc" 8 | 3. "def" 9 | 4. "ghi" 10 | 5. "jkl" 11 | 6. "mno" 12 | 7. "pqrs" 13 | 8. "tuv" 14 | 9. "wxyz" 15 | 16 | 17 | ##Example 1: 18 | ``` 19 | Input: digits = "23" 20 | Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] 21 | ``` 22 | 23 | ##Example 2: 24 | ``` 25 | Input: digits = "" 26 | Output: [] 27 | ``` 28 | 29 | ##Example 3: 30 | ``` 31 | Input: digits = "2" 32 | Output: ["a","b","c"] 33 | ``` 34 | 35 | ##Constraints: 36 | 37 | 0 <= digits.length <= 4 38 | digits[i] is a digit in the range ['2', '9']. 39 | 40 | Reference: [Leetcode Problem](https://leetcode.com/problems/letter-combinations-of-a-phone-number/) 41 | -------------------------------------------------------------------------------- /Programming/Python/GenerateParentheses/GenerateParentheses.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 3 | 4 | Example - 1: 5 | Input: n = 3 6 | Output: ["((()))","(()())","(())()","()(())","()()()"] 7 | """ 8 | 9 | class Solution(object): 10 | 11 | # Storing the generated string 12 | def generateParenthesis(self, n): 13 | result = [] 14 | self.generateRecurParen(n,n,"",result) 15 | return result 16 | 17 | # Recursive call to left and right paren 18 | def generateRecurParen(self, left,right,temp,result): 19 | if left == 0 and right == 0: 20 | result.append(temp) 21 | return 22 | if left>0: 23 | self.generateRecurParen(left-1,right,temp+'(',result) 24 | if right > left: 25 | self.generateRecurParen(left, right-1, temp + ')', result) 26 | 27 | # Making object 28 | object1 = Solution() 29 | n = int(input("Enter the number of pairs: ")) 30 | print(object1.generateParenthesis(n)) -------------------------------------------------------------------------------- /Programming/Python/RootsOfQuadraticEquation/RootsOfQuadraticEquation.py: -------------------------------------------------------------------------------- 1 | # Python program to find roots of quadratic equation 2 | from math import sqrt 3 | while 1: 4 | a = int(input('Value of a : ')) 5 | if a == 0: 6 | print('Not Quadratic Equation.') 7 | continue 8 | else: 9 | break 10 | b = int(input('Value of b : ')) 11 | c = int(input('Value of c : ')) 12 | 13 | 14 | 15 | # calculating discriminant using formula 16 | dis = b * b - 4 * a * c 17 | sqrt_val = sqrt(abs(dis)) 18 | 19 | # checking condition for discriminant 20 | if dis > 0: 21 | print(" real and different roots ") 22 | print((-b + sqrt_val)/(2 * a)) 23 | print((-b - sqrt_val)/(2 * a)) 24 | 25 | elif dis == 0: 26 | print(" real and same roots") 27 | print(-b / (2 * a)) 28 | 29 | # when discriminant is less than 0 30 | else: 31 | print("Complex Roots") 32 | print(- b / (2 * a), " + i", sqrt_val) 33 | print(- b / (2 * a), " - i", sqrt_val) 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: aditya109 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /Programming/Kotlin/TwoSum/TwoSum.kt: -------------------------------------------------------------------------------- 1 | package com.example.testapp 2 | 3 | import java.util.* 4 | 5 | fun main(){ 6 | val numbers = arrayListOf() 7 | val output = arrayListOf() 8 | val scanner = Scanner(System.`in`) 9 | 10 | println("Enter the size of the list") 11 | val listSize = scanner.nextInt() 12 | 13 | println("Enter the $listSize numbers in a non-decreasing sorted manner") 14 | for (i in 0 until listSize) numbers.add(scanner.nextInt()) 15 | 16 | println("Enter the target number") 17 | val targetNum = scanner.nextInt() 18 | 19 | outerLoop@ 20 | for (i in 0 until listSize){ 21 | for (j in i+1 until listSize){ 22 | if (numbers[i]+numbers[j] == targetNum){ 23 | output.addAll(arrayListOf(i+1,j+1)) 24 | break@outerLoop 25 | } 26 | } 27 | } 28 | 29 | if (output.isNotEmpty()) println("[${output[0]},${output[1]}]") 30 | else println("The list does not contain the required numbers to satisfy the condition") 31 | } -------------------------------------------------------------------------------- /Programming/Golang/TwoSum/TwoSum.go: -------------------------------------------------------------------------------- 1 | // Read the problem description here: https://github.com/aditya109/git-osp-for-beginners/issues/462 2 | 3 | package main 4 | 5 | import ( 6 | "errors" 7 | "fmt" 8 | ) 9 | 10 | // twoSum returns an int array of length 2 that contains the indices 11 | // of the numbers in array `arr` that add up to `target` 12 | func twoSum(target int, arr []int) ([2]int, error) { 13 | numMap := make(map[int]int) 14 | 15 | for i, num := range arr { 16 | numMap[num] = i 17 | } 18 | 19 | for i, num := range arr { 20 | if complement, ok := numMap[target-num]; ok { 21 | return [2]int{i + 1, complement + 1}, nil 22 | } 23 | } 24 | 25 | return [2]int{}, errors.New("No pair of numbers found in the array that add up to the target value") 26 | } 27 | 28 | // main function to test the `twoSum` algorithm 29 | func main() { 30 | array := []int{2, 7, 11, 15} 31 | target := 9 32 | 33 | res, err := twoSum(target, array) 34 | if err != nil { 35 | panic(err.Error()) 36 | } 37 | 38 | fmt.Println("Result is:", res) 39 | } 40 | -------------------------------------------------------------------------------- /Programming/JavaScript/Zigzag-Conversion/zigzagConversion.js: -------------------------------------------------------------------------------- 1 | function zigzag(s, n) { 2 | const arraySet = []; 3 | for (let i = 0; i < n; i++) { 4 | arraySet[i] = []; 5 | } 6 | 7 | let change = false; 8 | let count = 1; 9 | for (let i = 0; i < s.length; i++) { 10 | if (!change) { 11 | arraySet[count - 1].push(s.charAt(i)); 12 | } else { 13 | arraySet[n - count - 1].push(s.charAt(i)); 14 | } 15 | 16 | if ((count === n && !change) || (count === n - 2 && change)) { 17 | count = 0; 18 | change = !change; 19 | } 20 | count++; 21 | } 22 | 23 | let convertedString = ""; 24 | for (let i = 0; i < n; i++) { 25 | for (let j = 0; j < arraySet[i].length; j++) { 26 | convertedString = convertedString + arraySet[i][j]; 27 | } 28 | } 29 | 30 | return convertedString; 31 | } 32 | 33 | function main() { 34 | let s = "WE_ARE_HIRING"; 35 | var n = 4; 36 | /* eslint-disable no-console */ 37 | console.log(zigzag(s, n)); 38 | /* eslint-enable no-console */ 39 | } 40 | 41 | main(); 42 | -------------------------------------------------------------------------------- /Programming/Java/HighestFrequencyCharacter/HighestFrequencyCharacter.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | import java.util.HashMap; 3 | import java.util.Scanner; 4 | 5 | //Highest Frequency Character 6 | 7 | public class HighestFrequencyCharacter { 8 | public static void main(String[] args) { 9 | 10 | Scanner sc = new Scanner(System.in); 11 | String str = sc.nextLine(); 12 | 13 | HashMap hm = new HashMap<>(); 14 | for (int i = 0; i < str.length(); i++){ 15 | char ch = str.charAt(i); 16 | 17 | if (hm.containsKey(ch)){ 18 | int of = hm.get(ch); 19 | int nf = of+1; 20 | hm.put(ch,nf); 21 | } 22 | else{ 23 | hm.put(ch,1); 24 | } 25 | } 26 | 27 | char mfc = str.charAt(0); 28 | for (Character key : hm.keySet()){ 29 | if(hm.get(key)>hm.get(mfc)){ 30 | mfc=key; 31 | } 32 | } 33 | System.out.println(mfc); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Programming/Java/TriangleTripletsCounter/TriangleTripletsCounter.java: -------------------------------------------------------------------------------- 1 | public class TriangleTripltesCounter { 2 | 3 | public int triangleNumber(int[] nums) { 4 | int numResult = 0; 5 | int[] triplet = new int[3]; 6 | for (int i = 0; i < nums.length-2; i++){ 7 | for (int j = i+1; j < nums.length-1; j++){ 8 | for (int k = j+1; k < nums.length; k++){ 9 | triplet[0] = nums[i]; 10 | triplet[1] = nums[j]; 11 | triplet[2] = nums[k]; 12 | numResult += isTripletTriangle(triplet); 13 | } 14 | } 15 | } 16 | return numResult; 17 | } 18 | 19 | public int isTripletTriangle(int[] triplet){ 20 | if (triplet[0] + triplet[1] <= triplet[2]) 21 | return 0; 22 | else if (triplet[0] + triplet[2] <= triplet[1]) 23 | return 0; 24 | else if (triplet[1] + triplet[2] <= triplet[0]) 25 | return 0; 26 | else 27 | return 1; 28 | } 29 | } -------------------------------------------------------------------------------- /Programming/Python/MedianOfTwoSortedArrays/median_of_two_sorted_arrays.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | def find_median_of_merged_version_of_two_sorted_array(nums1,nums2): 5 | i =0 6 | j=0 7 | k=0 8 | merged = [ 0 for i in range(len(nums1)+len(nums2))] 9 | while i < len(nums1) and j < len(nums2): 10 | if nums1[i] < nums2[j]: 11 | merged[k] = nums1[i] 12 | i+= 1 13 | else: 14 | merged[k] = nums2[j] 15 | j+= 1 16 | k+= 1 17 | 18 | while i < len(nums1): 19 | merged[k] = nums1[i] 20 | i+= 1 21 | k+= 1 22 | 23 | while j < len(nums2): 24 | merged[k] = nums2[j] 25 | j+= 1 26 | k+= 1 27 | 28 | 29 | if len(merged)%2==0: 30 | _1=len(merged)/2-1 31 | _2=len(merged)/2 32 | return (merged[ _1]+merged[_2] )/2 33 | else: 34 | _1=int((len(merged)-1)/2) 35 | return merged[_1 ] 36 | 37 | 38 | find_median_of_merged_version_of_two_sorted_array([1,3],[2]) -------------------------------------------------------------------------------- /Programming/C#/Generate Parentheses/solution.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System; 4 | using System.Text; 5 | 6 | namespace GenerateParentheses 7 | { 8 | //more on: https://github.com/pakosel/leetcode-solutions 9 | public class Solution 10 | { 11 | List result = new List(); 12 | int maxLen; 13 | 14 | public IList GenerateParenthesis(int n) 15 | { 16 | maxLen = n; 17 | GenerateAndCheck("", 0, 0); 18 | return result; 19 | } 20 | 21 | private void GenerateAndCheck(string str, int opened, int closed) 22 | { 23 | if (opened == closed && opened == maxLen) 24 | { 25 | result.Add(str); 26 | return; 27 | } 28 | 29 | if (opened < maxLen) 30 | GenerateAndCheck(str + "(", opened + 1, closed); 31 | if (closed < opened) 32 | GenerateAndCheck(str + ")", opened, closed + 1); 33 | } 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Programming/Java/WordsStartWithVowels/CountingTheWordsStartingWithVowels.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class CountingTheWordsStartingWithVowels { 4 | public static void main(String[] args){ 5 | Scanner in = new Scanner(System.in); 6 | String sentence = in.nextLine(); 7 | int result = getWordsCount(sentence); 8 | System.out.println(result); 9 | } 10 | 11 | private static int getWordsCount(String sentence) { 12 | String[] words = sentence.split(" "); 13 | int count = 0; 14 | for (String word: words){ 15 | if(isStartingWithVowel(word)){ 16 | count++; 17 | } 18 | } 19 | return count; 20 | } 21 | 22 | private static boolean isStartingWithVowel(String word) { 23 | char firstLetter = word.toLowerCase().charAt(0); 24 | return firstLetter == 'a' || 25 | firstLetter =='e' || 26 | firstLetter == 'i' || 27 | firstLetter == 'o' || 28 | firstLetter == 'u'; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Programming/C++/Roman_To_Integer/Roman_To_Integer.cpp: -------------------------------------------------------------------------------- 1 | // Program to convert Roman to numerials 2 | #include 3 | using namespace std; 4 | 5 | int romanToInteger(char c) 6 | { 7 | switch(c) 8 | { 9 | case 'I' : return 1; 10 | case 'V' : return 5; 11 | case 'X' : return 10; 12 | case 'L' : return 50; 13 | case 'C' : return 100; 14 | case 'D' : return 500; 15 | case 'M' : return 1000; 16 | } 17 | return 0; 18 | } 19 | 20 | int romanToInt(string s) { 21 | int size = s.size(); 22 | if(size==0) 23 | return 0; 24 | int result = 0; 25 | for(int i=1; i romanToInteger(s[i-1]) ) 28 | result -= romanToInteger(s[i-1]); 29 | else 30 | result += (romanToInteger(s[i-1])); 31 | } 32 | result += romanToInteger(s.back()); 33 | return result; 34 | } 35 | 36 | // Driver Program 37 | int main() 38 | { 39 | // Considering inputs given are valid 40 | string str = "MCMIV"; 41 | cout << "Integer form of Roman Numeral is " 42 | << romanToInt(str) << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Programming/C/Generate Parenthesis/Generate_parenthesis.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | # include 4 | # define MAX_SIZE 100 5 | 6 | void _printParenthesis(int pos, int n, int open, int close); 7 | 8 | // Wrapper over _printParenthesis() 9 | void printParenthesis(int n) 10 | { 11 | if(n > 0) 12 | _printParenthesis(0, n, 0, 0); 13 | return; 14 | } 15 | 16 | void _printParenthesis(int pos, int n, int open, int close) 17 | { 18 | static char str[MAX_SIZE]; 19 | 20 | if(close == n) 21 | { 22 | printf("%s \n", str); 23 | return; 24 | } 25 | else 26 | { 27 | if(open > close) 28 | { 29 | str[pos] = ')'; 30 | _printParenthesis(pos+1, n, open, close+1); 31 | } 32 | 33 | if(open < n) 34 | { 35 | str[pos] = '('; 36 | _printParenthesis(pos+1, n, open+1, close); 37 | } 38 | } 39 | } 40 | 41 | 42 | int main() 43 | { 44 | int n; 45 | printf("Enter n : "); 46 | scanf("%d",&n); 47 | 48 | printParenthesis(n); 49 | getchar(); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Programming/Java/AnagramsOrNot/AnagramsOrNot.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AnagramsOrNot { 5 | 6 | static boolean isAnagram(String a, String b) { 7 | // Complete the function 8 | boolean result = true; 9 | int sz = 26; 10 | int [] count = new int[sz]; 11 | if(a.length()!=b.length()) result = false; 12 | for(int i=0;i0: 18 | return True 19 | else: 20 | return False 21 | 22 | input_list = input("Enter the numbers you want to add to your list : ") 23 | 24 | #the following line splits our input when a space is detected and convert into an element of a list 25 | final_list = input_list.split() 26 | 27 | #calling our functions 28 | if all(is_positive(x) for x in final_list): 29 | if any(is_palindrome(x) for x in final_list): 30 | print("True") 31 | else: 32 | print("False") 33 | -------------------------------------------------------------------------------- /Programming/Java/AnagramsOrNot/TwoStringsAnagrams.java: -------------------------------------------------------------------------------- 1 | package Programming.Java.Problem4; 2 | 3 | import java.util.*; 4 | 5 | public class TwoStringsAnagrams { 6 | public static void main(String[] args){ 7 | Scanner sc = new Scanner(System.in); 8 | String a = sc.nextLine(); 9 | String b = sc.nextLine(); 10 | isAnagram(a,b); 11 | sc.close(); 12 | } 13 | 14 | private static void isAnagram(String a, String b) { 15 | String s1 = a.replaceAll("\\s", ""); 16 | String s2 = b.replaceAll("\\s", ""); 17 | boolean status = true; 18 | if (s1.length() != s2.length()) { 19 | status = false; 20 | } else { 21 | char[] ArrayS1 = s1.toLowerCase().toCharArray(); 22 | char[] ArrayS2 = s2.toLowerCase().toCharArray(); 23 | Arrays.sort(ArrayS1); 24 | Arrays.sort(ArrayS2); 25 | status = Arrays.equals(ArrayS1, ArrayS2); 26 | } 27 | if (status) { 28 | System.out.println(s1 + " and " + s2 + " are anagrams"); 29 | } else { 30 | System.out.println(s1 + " and " + s2 + " are not anagrams"); 31 | } 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /Programming/Java/PassOrFail/PassOrFail.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class PassOrFail { 4 | public static void main(String[] args) { 5 | Scanner obj = new Scanner(System.in); 6 | String sn[] = new String[5]; 7 | int i; 8 | for (i = 0; i < 5; i++) { 9 | System.out.println("Enter the name of a student"); 10 | sn[i] = obj.nextLine(); 11 | } 12 | for (i = 0;; i++) { 13 | System.out.println("Enter the name of student whose result you want to find out"); 14 | String t = obj.nextLine(); 15 | 16 | if (t.compareToIgnoreCase("EXIT") == 0) { 17 | break; 18 | } else { 19 | int c = 0; 20 | for (i = 0; i < 5; i++) { 21 | if (t.compareToIgnoreCase(sn[i]) == 0) { 22 | System.out.println(t + " " + "Passed"); 23 | c = 1; 24 | break; 25 | } 26 | } 27 | if (c == 0) 28 | System.out.println(t + " " + "Failed"); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Programming/Kotlin/RemoveDuplicates/RemoveDuplicates.kt: -------------------------------------------------------------------------------- 1 | package com.example.testapp 2 | 3 | import java.util.* 4 | import kotlin.collections.ArrayList 5 | 6 | fun main(){ 7 | val scanner = Scanner(System.`in`) 8 | println("Enter the size of array") 9 | val size = scanner.nextInt() 10 | 11 | val nums = arrayListOf() 12 | println("Enter the $size numbers") 13 | for(i in 0 until size) nums.add(scanner.nextInt()) 14 | 15 | val k = removeDuplicates(nums) 16 | 17 | println("Size of the new array is $k") 18 | print("The new array is:\n[") 19 | for(num in nums){ 20 | if (num==nums[nums.size-1]) print("$num]") 21 | else print("$num,") 22 | } 23 | 24 | } 25 | 26 | fun removeDuplicates(nums : ArrayList): Int{ 27 | var size = nums.size 28 | var i = 0 29 | while (i 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | std::vector numbers; 8 | char answer; 9 | do 10 | { 11 | int number; 12 | 13 | std::cout << "Type a number to be inserted in the list: "; 14 | std::cin >> number; 15 | numbers.push_back(number); 16 | std::cout << std::endl << "Would you like to add other number to the list? (Y/N) "; 17 | std::cin >> answer; 18 | }while(answer != 'N'); 19 | 20 | std::cout << "This is the list of number that you've typed: " << std::endl; 21 | for(const auto& number: numbers){ 22 | std::cout << number << "\t"; 23 | } 24 | std::cout << std::endl; 25 | std::cout << "Please type the number that you want to search: "; 26 | int search; 27 | std::cin >> search; 28 | auto result = std::find(numbers.begin(), numbers.end(), search); 29 | 30 | std::cout << "The number " << search << " is "; 31 | if(result == numbers.end()) 32 | { 33 | std::cout << "NOT "; 34 | } 35 | std::cout << "contained in the list" << std::endl; 36 | } 37 | -------------------------------------------------------------------------------- /Programming/JavaScript/LetterCombinationsofaPhoneNumber/LetterCombinationsofaPhoneNumber.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} digits 3 | * @return {string[]} 4 | */ 5 | const LETTER_COMBINATIONS = { 6 | 2: ['a','b','c'], 7 | 3: ['d','e','f'], 8 | 4: ['g','h','i'], 9 | 5: ['j','k','l'], 10 | 6: ['m','n','o'], 11 | 7: ['p','q','r', 's'], 12 | 8: ['t','u','v'], 13 | 9: ['w','x','y', 'z'], 14 | } 15 | 16 | const letterCombinations = (digits) => { 17 | return digits.length ? buildLetterCombinations(digits, ['']) : [] 18 | }; 19 | 20 | const buildLetterCombinations = (digits, previousCombinations) => { 21 | const combinations = [] 22 | 23 | for (const previousCombination of previousCombinations) { 24 | for (const letter of LETTER_COMBINATIONS[digits[0]]) { 25 | combinations.push( 26 | previousCombination.concat(letter) 27 | ); 28 | } 29 | } 30 | 31 | return digits.length > 1 ? buildLetterCombinations(digits.slice(1), combinations) : combinations 32 | } 33 | 34 | console.log(letterCombinations('23')) 35 | console.log(letterCombinations('')) 36 | console.log(letterCombinations('2')) 37 | -------------------------------------------------------------------------------- /Programming/Python/ContainerWithMostWater/ContainerWithMostWater.py: -------------------------------------------------------------------------------- 1 | """ 2 | Question: Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). 3 | Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. 4 | 5 | Given Example 6 | Example 1: 7 | 8 | Input: height = [1,8,6,2,5,4,8,3,7] 9 | Output: 49 10 | """ 11 | 12 | 13 | def max_capacity(height): 14 | max_area = 0 15 | 16 | i = 0 17 | j = len(height) - 1 18 | 19 | # Using the two pointers namely i and j 20 | while i < j: 21 | curr_area = (j - i) * min(height[i], height[j]) 22 | max_area = max(max_area, curr_area) 23 | if height[i] <= height[j]: 24 | i = i + 1 25 | else: 26 | j = j - 1 27 | return max_area 28 | 29 | def main(): 30 | height = list(map(int,input().split(" "))) 31 | print(max_capacity(height)) 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | 37 | #Time Complexity = O(n) 38 | #Space Complexity = O(1) 39 | -------------------------------------------------------------------------------- /Programming/JavaScript/BFS/04.BFS.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Queue = require('./02.Queue'); 4 | const Graph = require('./03.Graph'); 5 | 6 | function bfs(graph, visited, node, result) { 7 | const queue = new Queue(); 8 | 9 | queue.enqueue(node); 10 | visited[node] = true; 11 | 12 | while (!queue.isEmpty()) { 13 | const front = queue.dequeue(); 14 | result.ans += front; 15 | 16 | let temp = graph.list[front].head; 17 | while (temp) { 18 | if (!visited[temp.data]) { 19 | queue.enqueue(temp.data); 20 | visited[temp.data] = true; 21 | } 22 | temp = temp.nextElement; 23 | } 24 | } 25 | } 26 | 27 | function bfsTraversal(g) { 28 | let result = { 29 | ans: '', 30 | }; 31 | let num_of_vertices = g.vertices; 32 | 33 | const visited = new Array(num_of_vertices).fill(false); 34 | 35 | for (let i = 0; i < num_of_vertices; i++) { 36 | if (!visited[i]) { 37 | bfs(g, visited, i, result); 38 | } 39 | } 40 | 41 | return result.ans; 42 | } 43 | 44 | let g1 = new Graph(6); 45 | g1.addEdge(1, 2); 46 | g1.addEdge(1, 3); 47 | g1.addEdge(2, 4); 48 | g1.addEdge(2, 5); 49 | console.log(bfsTraversal(g1, 0)); 50 | -------------------------------------------------------------------------------- /Programming/C++/MissingElement/ME.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int search_missing_element(long long int arr[],long long int low ,long long int high){ 5 | long long int mid; 6 | mid=(high+low)/2; 7 | // cout<>T; 29 | for ( int t=0;t>n; 32 | long long int arr[n-1]; 33 | for(i=0;i>arr[i]; 35 | } 36 | 37 | sort(arr,arr+n-1); 38 | MissingElement=search_missing_element(arr,1,n-1); 39 | 40 | cout< resultList=num>=1 && num<=8 ?generateParenthesisUtility(num):Arrays.asList("Enter number between 1 and 8"); 7 | System.out.println(resultList); 8 | } 9 | 10 | /* 11 | The idea behind this solution is to insert a closure "()" each time, by this way, you can never have incorrect answers, 12 | but will have a lot of duplications, so using Set to remove the same. 13 | */ 14 | 15 | public static List generateParenthesisUtility(int n) { 16 | /* 17 | base case is n=1 as 'n' can be between 1 and 8 18 | */ 19 | if(n==1) return new ArrayList(Arrays.asList("()")); 20 | Set set=new HashSet(); 21 | for(String str:generateParenthesisUtility(n-1)){ 22 | for(int i=0;i list = new ArrayList(set); 27 | return list; 28 | } 29 | } -------------------------------------------------------------------------------- /Programming/C/Anagram/anagram.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int check_anagram(char [], char []); 4 | 5 | int main() 6 | { 7 | char a[1000], b[1000]; 8 | 9 | printf("Enter two strings\n"); 10 | gets(a); 11 | gets(b); 12 | 13 | if (check_anagram(a, b)) 14 | { 15 | printf("The strings are anagrams.\n"); 16 | getch(); 17 | } 18 | else 19 | { 20 | printf("The strings aren't anagrams.\n"); 21 | getch(); 22 | } 23 | 24 | return 0; 25 | } 26 | 27 | int check_anagram(char a[], char b[]) 28 | { 29 | int first[26] = {0}, second[26] = {0}, c=0; 30 | 31 | // Calculating frequency of characters of the first string 32 | 33 | while (a[c] != '\0') 34 | { 35 | 36 | if(isupper(a[c])) 37 | { 38 | a[c]=tolower(a[c]); 39 | } 40 | 41 | first[a[c]-'a']++; 42 | 43 | c++; 44 | } 45 | 46 | c = 0; 47 | 48 | while (b[c] != '\0') 49 | { 50 | if(isupper(b[c])) 51 | { 52 | b[c]=tolower(b[c]); 53 | } 54 | 55 | second[b[c]-'a']++; 56 | 57 | c++; 58 | } 59 | 60 | // Comparing the frequency of characters 61 | 62 | for (c = 0; c < 26; c++) 63 | { 64 | 65 | if (first[c] != second[c]) 66 | { 67 | return 0; 68 | } 69 | } 70 | return 1; 71 | } 72 | -------------------------------------------------------------------------------- /Programming/Java/HighScorer/DisplayHighestRunsScored.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class DisplayHighestRunsScored { 4 | public static void main(String[] args) { 5 | Scanner obj = new Scanner(System.in); 6 | System.out.println("Enter the number of players: "); 7 | int numberOfPlayers = obj.nextInt(); 8 | obj.nextLine(); // https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo 9 | String cp[] = new String[numberOfPlayers]; 10 | int run[] = new int[numberOfPlayers]; 11 | String player = cp[0]; 12 | int maxScore; 13 | for (int i = 0; i < numberOfPlayers; i++) { 14 | System.out.println("Enter the name and runs scored by the cricket player : "); 15 | cp[i] = obj.nextLine(); 16 | run[i] = obj.nextInt(); 17 | obj.nextLine() ; 18 | } 19 | maxScore = -1; 20 | 21 | for (int i = 0; i < numberOfPlayers; i++) { 22 | if (run[i] > maxScore) { 23 | maxScore = run[i]; 24 | player = cp[i]; 25 | } 26 | } 27 | System.out.println("The name and runs scored by the cricket player : " + player + " " + maxScore); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Programming/Java/PalindromeOrNot/PalindromeChecker.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PalindromeChecker { 4 | 5 | public static void main(String args[]){ 6 | 7 | // Get number from user 8 | System.out.println("Enter a number : "); 9 | int x = new Scanner(System.in).nextInt(); 10 | 11 | // Check if x is palindrome 12 | if(isPalindrome(x)){ 13 | System.out.println(x + " is a palindrome"); 14 | }else{ 15 | System.out.println(x + " is not a palindrome"); 16 | } 17 | } 18 | 19 | // Given an integer x, return true if x is palindrome integer 20 | public static boolean isPalindrome(int x) { 21 | // Negative numbers can not be palindrome 22 | if (x < 0) return false; 23 | // 1-digit numbers are palindrome 24 | if (x < 10) return true; 25 | 26 | int palindrome = x; 27 | int reverse = 0; 28 | 29 | // The reverse of given x 30 | while (palindrome != 0) { 31 | int remainder = palindrome % 10; 32 | reverse *= 10 + remainder; 33 | palindrome /= 10; 34 | } 35 | 36 | // if x and reversed x is equal, return true 37 | if (x == reverse) 38 | return true; 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Programming/Java/Zoo/Zoo.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * This is our Zoo 4 | * 5 | * @author Yasas Sandeepa 6 | * @version 25-10-2020 7 | */ 8 | import java.util.Iterator; 9 | import java.util.LinkedList; 10 | 11 | public class Zoo { 12 | 13 | private LinkedList animalList; 14 | 15 | public Zoo() { 16 | this.animalList = new LinkedList(); 17 | } 18 | 19 | public LinkedList getAnimalList() { 20 | return animalList; 21 | } 22 | 23 | public void addAnimal(Animal animal) { 24 | this.getAnimalList().add(animal); 25 | 26 | } 27 | 28 | // todo: adding proper logic to get the animal 29 | public void feedAnimal(String name) { 30 | System.out.println("You are Feeding to " + name); 31 | } 32 | 33 | public void viewAnimals() { 34 | System.out.println("==========All animals in the ZOO==========="); 35 | LinkedList list = this.getAnimalList(); 36 | Iterator iterator = list.iterator(); 37 | while (iterator.hasNext()) { 38 | System.out.println(iterator.next()); 39 | } 40 | System.out.println("============================================"); 41 | System.out.println("Thank you!"); 42 | 43 | } 44 | //I removed the largestPopulation method 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Programming/Java/MergeSort/MergeSort.java: -------------------------------------------------------------------------------- 1 | package Programming.Java.MergeSort; 2 | 3 | public class MergeSort { 4 | 5 | public static void merge(int[] arr, int l, int mid, int r) { 6 | int[] b = new int[arr.length]; 7 | int i = l; 8 | int j = mid + 1; 9 | int k = l; 10 | while (i <= mid && j <= r) { 11 | if (arr[i] < arr[j]) { 12 | b[k] = arr[i]; 13 | i++; 14 | } else { 15 | b[k] = arr[j]; 16 | j++; 17 | } 18 | k++; 19 | } 20 | if (i > mid) { 21 | while (j <= r) { 22 | b[k] = arr[j]; 23 | k++; 24 | j++; 25 | } 26 | } else { 27 | while (i <= mid) { 28 | b[k] = arr[i]; 29 | k++; 30 | i++; 31 | } 32 | } 33 | for (k = l; k <= r; k++) { 34 | arr[k] = b[k]; 35 | } 36 | } 37 | 38 | public static void mergeSort(int[] arr, int l, int r) { 39 | if (l < r) { 40 | int mid = (l + r) / 2; 41 | mergeSort(arr, l, mid); 42 | mergeSort(arr, mid + 1, r); 43 | merge(arr, l, mid, r); 44 | } 45 | } 46 | 47 | public static void main(String[] args) { 48 | int[] arr = { 73, 188, 894, 915, 940, 616, 900, 548 }; 49 | mergeSort(arr, 0, arr.length - 1); 50 | for (int j : arr) 51 | System.out.print(j + " "); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Programming/C++/Kadanes/kadane.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | long long int T; 6 | cin>>T; 7 | for (long long int t=0;t>n; 12 | long long int arr[n]; 13 | NeagativeElements=true; 14 | for (long long int i=0;i>arr[i]; 17 | if(arr[i]>0) 18 | NeagativeElements=false; 19 | } 20 | // All the elements are negative 21 | if(NeagativeElements){ 22 | sum=arr[0]; 23 | for(long long int i=i;isum) 25 | sum=arr[i]; 26 | } 27 | 28 | cout<max_sum) 37 | max_sum=sum; 38 | 39 | if(sum<0) 40 | sum=0; 41 | } 42 | 43 | cout< 2 | 3 | int main() 4 | { 5 | 6 | int n1,n2,n3; //Array Size Declaration 7 | printf("\nEnter the size of first array "); 8 | scanf("%d",&n1); 9 | printf("\nEnter the size of second array "); 10 | scanf("%d",&n2); 11 | 12 | n3=n1+n2; 13 | printf("\nEnter the sorted array elements"); 14 | int a[n1],b[n2],c[n3]; //Array Declaration 15 | for(int i=0;ic[j]) 36 | { 37 | temp=c[i]; 38 | c[i]=c[j]; 39 | c[j]=temp; 40 | } 41 | } 42 | } 43 | 44 | for(int i=0 ; i 5 | 6 | // Prints a maximum set of activities that can be done by a single 7 | // person, one at a time. 8 | // n --> Total number of activities 9 | // s[] --> An array that contains start time of all activities 10 | // f[] --> An array that contains finish time of all activities 11 | void printMaxActivities(int s[], int f[], int n) 12 | { 13 | int i, j; 14 | 15 | printf("Following activities are selected n"); 16 | 17 | // The first activity always gets selected 18 | i = 0; 19 | printf("%d ", i); 20 | 21 | // Consider rest of the activities 22 | for (j = 1; j < n; j++) 23 | { 24 | // If this activity has start time greater than or 25 | // equal to the finish time of previously selected 26 | // activity, then select it 27 | if (s[j] >= f[i]) 28 | { 29 | printf("%d ", j); 30 | i = j; 31 | } 32 | } 33 | } 34 | 35 | // driver program to test above function 36 | int main() 37 | { 38 | int s[] = {1, 3, 0, 5, 8, 5}; 39 | int f[] = {2, 4, 6, 7, 9, 9}; 40 | int n = sizeof(s) / sizeof(s[0]); 41 | printMaxActivities(s, f, n); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Programming/C++/Maximum_Gap/MaximumGap.cpp: -------------------------------------------------------------------------------- 1 | /*Issue #309 Finding maximum difference between two successive elements of a sorted array*/ 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | //Function for sorting 7 | void insertionSort(int arr[], int n) 8 | { 9 | int i, key, j; 10 | for(i=1;i=0 && arr[j]>key) 16 | { 17 | arr[j+1]=arr[j]; 18 | j=j-1; 19 | } 20 | arr[j+1]=key; 21 | } 22 | } 23 | //Function to find maximum difference 24 | int maxDiff(int arr[], int n) 25 | { 26 | int tempDiff; 27 | int maxDiff=arr[1]-arr[0]; 28 | int i; 29 | for(i=2; imaxDiff) 33 | { 34 | maxDiff=tempDiff; 35 | } 36 | } 37 | return maxDiff; 38 | } 39 | int main() 40 | { 41 | int i,n, maxD=0; 42 | cout<<"\nEnter size of the array (must be greater than 2): "; 43 | cin>>n; 44 | int *arr=new int[n]; 45 | cout<<"\nEnter the elements of the array\n"; 46 | for(i=0;i>arr[i]; 49 | } 50 | insertionSort(arr,n); 51 | maxD=maxDiff(arr, n); 52 | cout<<"\nMaximum Difference is "< 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | #define N 4UL 7 | int t[21][(1 << 21)]; 8 | // If all cities have been visited 9 | int VISITED_ALL = (1 << N) - 1; 10 | int tsp(array, N> const& graph, int mask, int i) { 11 | if (mask == VISITED_ALL) { 12 | return graph[i][0]; 13 | } 14 | // if already visited 15 | if (t[i][mask] != -1) { 16 | return t[i][mask]; 17 | } 18 | int ans = INT_MAX; 19 | // Try to goto an unvisited city 20 | for (size_t city = 0; city < N; city++) { 21 | if ((mask & (1 << city)) == 0) { 22 | ans = min(ans, graph[i][city] + tsp(graph, mask ^ (1 << city), city)); 23 | } 24 | } 25 | 26 | return t[i][mask] = ans; // saving and return the ans 27 | } 28 | int main() { 29 | ios_base::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | memset(&t, -1, sizeof t); 32 | // Adj matrix which defines the graph 33 | array, N> graph = {{ 34 | {0, 20, 42, 25}, 35 | {20, 0, 30, 34}, 36 | {42, 30, 0, 10}, 37 | {25, 34, 10, 0}, 38 | }}; 39 | cout << tsp(graph, 1, 0); // initial mask = 0001, initial city = 0 40 | // 85; 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Programming/Java/Palindrome/Palindrome.java: -------------------------------------------------------------------------------- 1 | package com.kholood; 2 | import java.util.Scanner; 3 | import java.lang.String; 4 | 5 | public class palindrome { 6 | 7 | public static void main(String [] args){ 8 | 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the number: "); 11 | String reverse = ""; 12 | String num = sc.nextLine(); 13 | int length = num.length(); 14 | 15 | for( int i = length - 1; i >= 0; i-- ) 16 | reverse = reverse + num.charAt(i); 17 | if (num.equals(reverse)) 18 | System.out.println("The entered string " +num +" is a palindrome."); 19 | else 20 | System.out.println("The entered string " +num +" isn't a palindrome."); 21 | 22 | System.out.print("Enter the string you want to check: "); 23 | String original = sc.nextLine(); 24 | int n = original.length(); 25 | String reversestring=""; 26 | for(int i = n - 1; i >= 0; i--) 27 | { 28 | reversestring = reversestring + original.charAt(i); 29 | } 30 | if(original.equalsIgnoreCase(reversestring)) 31 | System.out.println("The string is palindrome."); 32 | else 33 | System.out.println("The string is not palindrome."); 34 | 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Programming/Java/Palindrome/palindrome.java: -------------------------------------------------------------------------------- 1 | package com.kholood; 2 | import java.util.Scanner; 3 | import java.lang.String; 4 | 5 | public class palindrome { 6 | 7 | public static void main(String [] args){ 8 | 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the number: "); 11 | String reverse = ""; 12 | String num = sc.nextLine(); 13 | int length = num.length(); 14 | 15 | for( int i = length - 1; i >= 0; i-- ) 16 | reverse = reverse + num.charAt(i); 17 | if (num.equals(reverse)) 18 | System.out.println("The entered string " +num +" is a palindrome."); 19 | else 20 | System.out.println("The entered string " +num +" isn't a palindrome."); 21 | 22 | System.out.print("Enter the string you want to check: "); 23 | String original = sc.nextLine(); 24 | int n = original.length(); 25 | String reversestring=""; 26 | for(int i = n - 1; i >= 0; i--) 27 | { 28 | reversestring = reversestring + original.charAt(i); 29 | } 30 | if(original.equalsIgnoreCase(reversestring)) 31 | System.out.println("The string is palindrome."); 32 | else 33 | System.out.println("The string is not palindrome."); 34 | 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Programming/Golang/GenerateParentheses/GenerateParentheses.go: -------------------------------------------------------------------------------- 1 | // Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 2 | 3 | //Steps: 1. Add left paren only when open < n and right paren only when close < open 4 | 5 | package main 6 | 7 | import "fmt" 8 | 9 | func main() { 10 | // Taking Example Input- 1 11 | output := generateParenthesis(3) 12 | fmt.Println(output) 13 | 14 | // Taking Example Input-2 15 | output = generateParenthesis(1) 16 | fmt.Println(output) 17 | 18 | } 19 | 20 | //Priting the pairs 21 | func generateParenthesis(n int) []string { 22 | input := "" 23 | for i := 0; i < n; i++ { 24 | input = input + " " 25 | } 26 | output := generateParenthesisUtil(0, n, 0, 0, []rune(input)) 27 | return output 28 | } 29 | 30 | //Recursive Function 31 | func generateParenthesisUtil(pos, n, open, close int, input []rune) []string { 32 | 33 | var output []string 34 | if pos == n*2 { 35 | output = append(output, string(input)) 36 | return output 37 | } 38 | 39 | if close < open { 40 | input[pos] = ')' 41 | result := generateParenthesisUtil(pos+1, n, open, close+1, input) 42 | output = append(output, result...) 43 | 44 | } 45 | 46 | if open < n { 47 | input[pos] = '(' 48 | result := generateParenthesisUtil(pos+1, n, open+1, close, input) 49 | output = append(output, result...) 50 | } 51 | 52 | return output 53 | } 54 | -------------------------------------------------------------------------------- /Programming/C++/MergeSortedArray/MergeSortedArrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | vector merge(vector a, vector b, int m, int n) 7 | { 8 | 9 | vector res; 10 | res.resize(m + n); 11 | 12 | int i = 0, j = 0, k = 0; 13 | 14 | while (i < m && j < n) 15 | { 16 | 17 | (a[i] <= b[j]) ? res[k++] = a[i++] : res[k++] = b[j++]; 18 | } 19 | while (i < m) 20 | { 21 | res[k++] = a[i++]; 22 | } 23 | while (j < n) 24 | { 25 | res[k++] = b[j++]; 26 | } 27 | 28 | return res; 29 | } 30 | 31 | int main() 32 | { 33 | 34 | int m, n; 35 | vector arr1, arr2, res; 36 | 37 | cout << "Enter size for first array:"; 38 | cin >> m; 39 | 40 | cout << "Enter size for second array:"; 41 | cin >> n; 42 | 43 | arr1.resize(m); 44 | arr2.resize(n); 45 | res.resize(m + n); 46 | 47 | cout << "Enter first array:"; 48 | for (int i = 0; i < m; i++) 49 | cin >> arr1[i]; 50 | 51 | cout << "Enter second array:"; 52 | for (int j = 0; j < n; j++) 53 | cin >> arr2[j]; 54 | 55 | res = merge(arr1, arr2, m, n); 56 | 57 | cout << "Merged array:"; 58 | for (int l = 0; l < res.size(); l++) 59 | cout << res[l] << " "; 60 | 61 | return 0; 62 | } -------------------------------------------------------------------------------- /Programming/Java/AnagramsOrNot/IsAnagram.java: -------------------------------------------------------------------------------- 1 | package isAnagram; 2 | 3 | 4 | 5 | import java.util.Scanner; 6 | public class IsAnagram { 7 | 8 | 9 | static boolean isAnagram(String s1, String s2) { 10 | // Complete the function 11 | boolean isanagram=false; 12 | if(s1.length()==s2.length()){ 13 | int x=s1.length(); 14 | boolean[] v=new boolean[x]; 15 | 16 | for(int i=0;i twoSum(vector& numbers, int target) 4 | { 5 | int n = numbers.size(); // size of the array 6 | 7 | // Initially, start points to the start of the array and end points to the end. 8 | int start = 0, end = n-1; 9 | while (start < end) 10 | { 11 | 12 | if (numbers[start] + numbers[end] == target) 13 | { 14 | // Sum of values at start and end equals target 15 | return {start+1, end+1}; 16 | } 17 | else if (numbers[start] + numbers[end] < target) 18 | { 19 | // sum is less than target: In such cases we need to increase sum. 20 | // since the array is sorted in non-decreasing order, upon decreasing end pointer we would decrease the value of sum so 21 | // we should increase start pointer's value 22 | start++; 23 | } 24 | else 25 | { 26 | // sum > target: We should try to decrease sum. 27 | // since the array is sorted in non-decreasing order, we should decrease end pointer's value. 28 | end--; 29 | } 30 | } 31 | 32 | // it is guaranteed that there exists exactly one solution so we would not reach this point. 33 | return {0, 0}; 34 | } 35 | }; -------------------------------------------------------------------------------- /Programming/Golang/ContainerWithMostWater/container_with_most_water.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Problem statement : 4 | // Given n non-negative integers a1, a2, ..., an , 5 | // where each represents a point at coordinate (i, ai). 6 | // n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). 7 | // Find two lines, which, together with the x-axis forms a container, 8 | // such that the container contains the most water. 9 | 10 | import ( 11 | "fmt" 12 | ) 13 | 14 | func Min(x, y uint) uint { 15 | if x > y { 16 | return y 17 | } 18 | return x 19 | } 20 | 21 | func Max(x, y uint) uint { 22 | if x > y { 23 | return x 24 | } 25 | return y 26 | } 27 | 28 | func maxArea(heights []uint) uint { 29 | l := uint(0) 30 | r := uint(len(heights) - 1) 31 | area := uint(0) 32 | for l < r { 33 | area = Max(area, Min(heights[l], heights[r])*(r-l)) 34 | 35 | if heights[l] < heights[r] { 36 | l = l + 1 37 | } else { 38 | r = r - 1 39 | } 40 | } 41 | 42 | return area 43 | } 44 | 45 | func main() { 46 | fmt.Print("Enter the number of inputs : ") 47 | var inputCount uint 48 | fmt.Scanln(&inputCount) 49 | heights := make([]uint, inputCount) 50 | 51 | for i := uint(0); i < inputCount; i++ { 52 | fmt.Printf("Enter height of %d column: ", i+1) 53 | var temp uint 54 | fmt.Scanln(&temp) 55 | heights[i] = temp 56 | } 57 | 58 | fmt.Printf("The maximum Area of water is : %d \n", maxArea(heights)) 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Programming/JavaScript/BFS/03.Graph.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const LinkedList = require('./01.LinkedList'); 3 | 4 | module.exports = class Graph { 5 | constructor(vertices) { 6 | this.vertices = vertices; 7 | 8 | this.list = []; 9 | 10 | var it; 11 | for (it = 0; it < vertices; it++) { 12 | let temp = new LinkedList(); 13 | this.list.push(temp); 14 | } 15 | } 16 | 17 | addEdge(source, destination) { 18 | if (source < this.vertices && destination < this.vertices) 19 | this.list[source].insertAtHead(destination); 20 | return this; 21 | } 22 | 23 | printGraph() { 24 | console.log('>>Adjacency List of Directed Graph<<'); 25 | var i; 26 | for (i = 0; i < this.list.length; i++) { 27 | process.stdout.write('|' + String(i) + '| => '); 28 | let temp = this.list[i].getHead(); 29 | while (temp != null) { 30 | process.stdout.write('[' + String(temp.data) + '] -> '); 31 | temp = temp.nextElement; 32 | } 33 | console.log('null '); 34 | } 35 | } 36 | 37 | strGraph() { 38 | let str = ''; 39 | var i; 40 | for (i = 0; i < this.list.length; i++) { 41 | str = str + '|' + String(i) + '| => '; 42 | let temp = this.list[i].getHead(); 43 | while (temp != null) { 44 | str += '[' + String(temp.data) + '] -> '; 45 | temp = temp.nextElement; 46 | } 47 | str += 'null '; 48 | } 49 | return str; 50 | } 51 | }; 52 | -------------------------------------------------------------------------------- /Programming/Java/Integer to Roman/IntegertoRoman.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.*; 3 | public class Main 4 | { 5 | public static void main (String[]args) 6 | { 7 | Scanner s = new Scanner (System.in); 8 | String roman; 9 | System.out.println ("Enter a roman Number"); 10 | roman = s.nextLine (); 11 | RomantoInteger rm = new RomantoInteger (); 12 | rm.romantointeger (roman); 13 | 14 | } 15 | 16 | static class RomantoInteger 17 | { 18 | 19 | void romantointeger (String s) 20 | { 21 | int total = 0; 22 | for (int i = 0; i < s.length (); i++) 23 | { 24 | int s1 = digitval (s.charAt (i)); 25 | if (i + 1 < s.length ()) 26 | { 27 | int s2 = digitval (s.charAt (i + 1)); 28 | if (s1 >= s2) 29 | { 30 | total = total + s1; 31 | } 32 | else 33 | { 34 | total = total - s1; 35 | } 36 | } 37 | else 38 | { 39 | total = total + s1; 40 | } 41 | } 42 | System.out.println ("Output: " + total); 43 | } 44 | 45 | 46 | int digitval (char r) 47 | { 48 | 49 | if (r == 'I') 50 | return 1; 51 | if (r == 'V') 52 | return 5; 53 | if (r == 'X') 54 | return 10; 55 | if (r == 'L') 56 | return 50; 57 | if (r == 'C') 58 | return 100; 59 | if (r == 'D') 60 | return 500; 61 | if (r == 'M') 62 | return 1000; 63 | return -1; 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Programming/Java/LongestPalindromicSubstring/LongestPalindromicSubstring.java: -------------------------------------------------------------------------------- 1 | public class LongestPalindromicSubstring { 2 | public String expandPalindrome(String s, int left, int right, String curr_pali, int i){ 3 | while (s.charAt(left) == s.charAt(right)){ 4 | 5 | if (curr_pali.length() == 0) 6 | if (left == right) 7 | curr_pali = s.charAt(i) + ""; 8 | else 9 | curr_pali = s.charAt(left) + "" + s.charAt(right); 10 | else 11 | curr_pali = s.charAt(left) + curr_pali + s.charAt(right); 12 | left --; 13 | right ++; 14 | 15 | if (left < 0 || right >= s.length()) 16 | break; 17 | } 18 | return curr_pali; 19 | } 20 | 21 | 22 | public String longestPalindrome(String s) { 23 | String max_Pali = ""; 24 | 25 | for(int i = 0; i < s.length(); i++) { 26 | String pali_odd= ""; 27 | String pali_even = ""; 28 | 29 | pali_odd = expandPalindrome(s, i, i, pali_odd, i); 30 | if (i+1 < s.length()) 31 | pali_even = expandPalindrome(s, i, i+1, pali_even, i); 32 | 33 | if (pali_odd.length() > max_Pali.length()) 34 | max_Pali = pali_odd; 35 | 36 | if (pali_even.length() > max_Pali.length()) 37 | max_Pali = pali_even; 38 | } 39 | return max_Pali; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Programming/Java/RemoveDuplicates/removeduplicates.java: -------------------------------------------------------------------------------- 1 | class removeduplicates 2 | { 3 | // Function to remove duplicate elements 4 | // This function returns new size of modified 5 | // array. 6 | static int removeDuplicates(int arr[], int n) 7 | { 8 | // Return, if array is empty 9 | // or contains a single element 10 | if (n==0 || n==1) 11 | return n; 12 | 13 | int[] temp = new int[n]; 14 | 15 | // Start traversing elements 16 | int j = 0; 17 | for (int i=0; i0 and n> 0: 6 | #checking from the last-most element of nums1 and nums2 7 | if nums1[m-1]0: 19 | nums1[last_index] = nums2[n-1] 20 | n-=1 21 | last_index-=1 22 | 23 | 24 | return nums1 25 | 26 | 27 | 28 | nums1 = [] 29 | nums2 = [] 30 | 31 | # number of elements as input 32 | m = int(input("Enter size of first list : ")) 33 | n = int(input("Enter size of second list : ")) 34 | 35 | 36 | print("Enter first list elements") 37 | for i in range(0, m+n): 38 | if i 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | vector res; 8 | void possibleCombinations(string &digit,int index,unordered_map &map,string &ans){ 9 | if(index == digit.length()){ 10 | res.push_back(ans); 11 | return; 12 | } 13 | int current = digit[index] - '0'; 14 | string output = map[current]; 15 | for(int j=0; j letterCombinations(string digits) { 22 | if(digits == "") 23 | return {}; 24 | unordered_map map; 25 | map[2] = "abc"; 26 | map[3] = "def"; 27 | map[4] = "ghi"; 28 | map[5] = "jkl"; 29 | map[6] = "mno"; 30 | map[7] = "pqrs"; 31 | map[8] = "tuv"; 32 | map[9] = "wxyz"; 33 | string ans = ""; 34 | possibleCombinations(digits,0,map,ans); 35 | return res; 36 | } 37 | int main() 38 | { 39 | string digits; 40 | cout << "Type digits in range of (2,9)"; 41 | cin >> digits; 42 | vector fRes; 43 | fRes = letterCombinations(digits); 44 | for(auto i = fRes.begin(); i != fRes.end(); i++) { 45 | cout<< *i << " "; 46 | } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Programming/C++/Maximum_Gap/Maximum_Gap.cpp: -------------------------------------------------------------------------------- 1 | // CPP program to find maximum adjacent difference 2 | // between two adjacent after sorting. 3 | #include 4 | using namespace std; 5 | 6 | int maximumGap(vector& nums) { 7 | int n = nums.size(); 8 | if (n < 2) return 0; 9 | auto lu = minmax_element(nums.begin(), nums.end()); 10 | int l = *lu.first, u = *lu.second; 11 | int gap = max((u - l) / (n - 1), 1); 12 | int m = (u - l) / gap + 1; 13 | vector bucketsMin(m, INT_MAX); 14 | vector bucketsMax(m, INT_MIN); 15 | for (int num : nums) { 16 | int k = (num - l) / gap; 17 | if (num < bucketsMin[k]) bucketsMin[k] = num; 18 | if (num > bucketsMax[k]) bucketsMax[k] = num; 19 | } 20 | int i = 0, j; 21 | gap = bucketsMax[0] - bucketsMin[0]; 22 | while (i < m) { 23 | j = i + 1; 24 | while (j < m && bucketsMin[j] == INT_MAX && bucketsMax[j] == INT_MIN) 25 | j++; 26 | if (j == m) break; 27 | gap = max(gap, bucketsMin[j] - bucketsMax[i]); 28 | i = j; 29 | } 30 | return gap; 31 | } 32 | 33 | int main() 34 | { 35 | int size, element; 36 | vector arr; 37 | cin>>size; 38 | for(int i=0; i>element; 40 | arr.push_back(element); 41 | } 42 | cout << maximumGap(arr) << endl; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Programming/JavaScript/MaximumGap/Maximumgap.js: -------------------------------------------------------------------------------- 1 | // Maximum gap in a adjacent element in an Array. 2 | 3 | function merge(leftArr, rightArr) { 4 | let sortedArr = []; 5 | while (leftArr.length && rightArr.length) { 6 | if (leftArr[0] <= rightArr[0]) { 7 | sortedArr.push(leftArr[0]); 8 | leftArr = leftArr.slice(1) 9 | } else { 10 | sortedArr.push(rightArr[0]); 11 | rightArr = rightArr.slice(1) 12 | } 13 | } 14 | while (leftArr.length) 15 | sortedArr.push(leftArr.shift()); 16 | while (rightArr.length) 17 | sortedArr.push(rightArr.shift()); 18 | return sortedArr; 19 | } 20 | function mergesort(arr) { 21 | if (arr.length < 2) { 22 | return arr; 23 | } 24 | else { 25 | let midpoint = parseInt(arr.length / 2); 26 | let leftArr = arr.slice(0, midpoint); 27 | let rightArr = arr.slice(midpoint, arr.length); 28 | return merge(mergesort(leftArr), mergesort(rightArr)); 29 | } 30 | } 31 | function maximumGap(arr) { 32 | let length = arr.length(); 33 | if (length < 3) { 34 | return 0 35 | } 36 | sortedArry = mergesort(arr); 37 | for (let index = 0; index < length - 1; index++){ 38 | diff_arr[index] = arr[length - index - 1]-arr[length - index - 2]; 39 | if (diff_arr[index] > max_diff){ 40 | max_diff=diff_arr[index]; 41 | } 42 | } 43 | return max_diff 44 | } 45 | let arr = [2, 13, 7, 3, 5] 46 | maximumGap(arr); // returns 6 47 | let arr = [12, 53] 48 | maximumGap(arr); // returns 0 49 | -------------------------------------------------------------------------------- /Programming/Java/DisplayPrimes/DisplayPrimeArrayElements.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class DisplayPrimeArrayElements { 4 | public static void main(String[] args){ 5 | Scanner in = new Scanner(System.in); 6 | int n = in.nextInt(); // can be between 1 - 10^6 7 | int input[] = new int[n]; 8 | for (int i =0; i array[j]) 26 | { 27 | int aux = array[i]; 28 | array[i] = array[j]; 29 | array[j] = aux; 30 | } 31 | 32 | int maxGap = 0; 33 | 34 | if(arraySize >= 2) { 35 | for (int i = 0; i < arraySize - 1; i++) 36 | if (array[i] - array[i + 1] > maxGap) 37 | maxGap = array[i] - array[i + 1]; 38 | } 39 | 40 | Console.WriteLine(); 41 | Console.WriteLine("Max gap: {0}", maxGap); 42 | 43 | Console.WriteLine(); 44 | Console.WriteLine("Press enter to close..."); 45 | Console.ReadLine(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Programming/Java/MedianOfTwoSortedArrays/MedianOfTwoSortedArrays.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class MedianOfTwoSortedArrays 4 | 5 | { public static void main(String[] args) 6 | { 7 | Scanner scan = new Scanner(System.in); 8 | System.out.println("Enter number of elements in arrays"); 9 | int N = scan.nextInt(); 10 | int[] nums1 = new int[ N ]; 11 | int[] nums2 = new int[ N ]; 12 | System.out.println("Enter "+ N +" elements of array 1"); 13 | for (int i = 0; i < N; i++) 14 | nums1[i] = scan.nextInt(); 15 | System.out.println("Enter "+ N +" elements of array 2"); 16 | for (int i = 0; i < N; i++) 17 | nums2[i] = scan.nextInt(); 18 | int med = median(nums1, nums2); 19 | System.out.println("Median = "+ med); 20 | } 21 | public static int median(int[] nums1, int[] nums2) 22 | { 23 | int N = nums1.length; 24 | return median(nums1, 0, N -1 , nums2, 0, N - 1); 25 | } 26 | public static int median(int[] nums1, int l1, int h1, int[] nums2, int l2, int h2) 27 | { 28 | int mid1 = (h1 + l1 ) / 2; 29 | int mid2 = (h2 + l2 ) / 2; 30 | 31 | if (h1 - l1 == 1) 32 | return (Math.max(nums1[l1] , nums2[l2]) + Math.min(nums1[h1] , nums2[h2]))/2; 33 | else if (nums1[mid1] > nums2[mid2]) 34 | return median(nums1, l1, mid1 , nums2, mid2 , h2); 35 | else 36 | return median(nums1, mid1 , h1, nums2, l2 , mid2 ); 37 | } 38 | } -------------------------------------------------------------------------------- /Programming/C++/LongestPalindromicSubstring/LongestPalindromicSubstring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void printSubStr(char *str, int low, int high) 5 | { 6 | for (int i = low; i <= high; ++i) 7 | cout << str[i]; 8 | 9 | cout << endl; 10 | } 11 | 12 | int longestPalSubstr(char *str) 13 | { 14 | int maxLength = 1; 15 | 16 | int start = 0; 17 | int len = strlen(str); 18 | 19 | int low, high; 20 | 21 | for (int i = 1; i < len; ++i) 22 | { 23 | low = i - 1; 24 | high = i; 25 | while (low >= 0 && high < len && str[low] == str[high]) 26 | { 27 | if (high - low + 1 > maxLength) 28 | { 29 | start = low; 30 | maxLength = high - low + 1; 31 | } 32 | --low; 33 | ++high; 34 | } 35 | 36 | low = i - 1; 37 | high = i + 1; 38 | 39 | while (low >= 0 && high < len && str[low] == str[high]) 40 | { 41 | if (high - low + 1 > maxLength) 42 | { 43 | start = low; 44 | maxLength = high - low + 1; 45 | } 46 | --low; 47 | ++high; 48 | } 49 | } 50 | 51 | cout << "Longest palindrome substring is: "; 52 | printSubStr(str, start, start + maxLength - 1); 53 | 54 | return maxLength; 55 | } 56 | 57 | int main() 58 | { 59 | string s; 60 | cin >> s; 61 | int n = s.length(); 62 | char str[n + 1]; 63 | strcpy(str, s.c_str()); 64 | longestPalSubstr(str); 65 | return 0; 66 | } -------------------------------------------------------------------------------- /Programming/C#/longest_substring/longest substring.cs: -------------------------------------------------------------------------------- 1 | // C# program to find the length of the 2 | // longest substring without repeating 3 | // characters 4 | using System; 5 | 6 | class GFG{ 7 | 8 | // This function returns true if all characters in 9 | // str[i..j] are distinct, otherwise returns false 10 | public static bool areDistinct(string str, 11 | int i, int j) 12 | { 13 | 14 | // Note : Default values in visited are false 15 | bool[] visited = new bool[26]; 16 | 17 | for(int k = i; k <= j; k++) 18 | { 19 | if (visited[str[k] - 'a'] == true) 20 | return false; 21 | 22 | visited[str[k] - 'a'] = true; 23 | } 24 | return true; 25 | } 26 | 27 | // Returns length of the longest substring 28 | // with all distinct characters. 29 | public static int longestUniqueSubsttr(string str) 30 | { 31 | int n = str.Length; 32 | 33 | // Result 34 | int res = 0; 35 | 36 | for(int i = 0; i < n; i++) 37 | for(int j = i; j < n; j++) 38 | if (areDistinct(str, i, j)) 39 | res = Math.Max(res, j - i + 1); 40 | 41 | return res; 42 | } 43 | 44 | // Driver code 45 | public static void Main() 46 | { 47 | string str = "abcabcbb"; 48 | Console.WriteLine("The input string is " + str); 49 | 50 | int len = longestUniqueSubsttr(str); 51 | 52 | Console.WriteLine("The length of the longest " + "non-repeating character " + "substring is " + len); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Programming/Java/CheckPsswdStrongOrNot/StrongPsswd.java: -------------------------------------------------------------------------------- 1 | /*If the password is strong then it should return True and if the password is not strong enough then it should return False. 2 | Here are the conditions for the password to be strong: 3 | 4 | Its length is at least 8. 5 | It contains at least one digit. 6 | It contains at least one lowercase English character. 7 | It contains at least one uppercase English character. 8 | It contains at least one special character. The special characters are: !@#$%^&*()-+ 9 | "ADG787gbujI^%^%T&g" will output True 10 | "AGjy%^>f" will output False 11 | */ 12 | public class StrongPsswd { 13 | public static void main(String[] args) { 14 | String pswd="AGjy%^>f"; 15 | boolean b= PsswdStrong(pswd); 16 | System.out.println(b); 17 | } 18 | public static boolean PsswdStrong(String pswd){ 19 | boolean b=false; 20 | if(pswd.length()<8){ 21 | return false; 22 | } 23 | if(pswd.contains(" ")){ 24 | return false; 25 | } 26 | if( pswd.matches("(?=.*[a-z]).*") ){ 27 | if(pswd.matches("(?=.*[A-Z]).*")){ 28 | if(pswd.matches("(?=.*[0-9]).*") ){ 29 | if(pswd.contains("!")||pswd.contains("@")||pswd.contains("#")||pswd.contains("$")||pswd.contains("%")||pswd.contains("^")||pswd.contains("&")||pswd.contains("*")||pswd.contains("(")||pswd.contains(")")||pswd.contains("+")||pswd.contains("-")){ 30 | b=true; 31 | } 32 | } 33 | } 34 | } 35 | return b; 36 | } 37 | } -------------------------------------------------------------------------------- /Programming/Java/DiceThrowProblem/Dice_Throw_Problem.java: -------------------------------------------------------------------------------- 1 | /* PROBLEM STATEMENT: Given n dice each with m faces, numbered from 1 to m, find the number of ways to get sum X. X is the summation of 2 | values on each face when all the dice are thrown. 3 | 4 | Time Complexity: O(m * n * x) where m is number of faces, n is number of dice and x is given sum. */ 5 | 6 | 7 | import java.util.*; 8 | import java.lang.*; 9 | import java.io.*; 10 | 11 | class GFG { 12 | 13 | public static long findWays(int m, int n, int x){ 14 | 15 | /* Create a table to store the results of subproblems. 16 | One extra row and column are used for simplicity 17 | (Number of dice is directly used as row index and sum is directly used as column index). 18 | The entries in 0th row and 0th column are never used. */ 19 | long[][] table = new long[n+1][x+1]; 20 | 21 | /* Table entries for only one dice */ 22 | for(int j = 1; j <= m && j <= x; j++) 23 | table[1][j] = 1; 24 | 25 | /* Fill rest of the entries in table using recursive relation 26 | i: number of dice, j: sum */ 27 | for(int i = 2; i <= n;i ++){ 28 | for(int j = 1; j <= x; j++){ 29 | for(int k = 1; k < j && k <= m; k++) 30 | table[i][j] += table[i-1][j-k]; 31 | } 32 | } 33 | 34 | 35 | return table[n][x]; 36 | } 37 | 38 | public static void main (String[] args) { 39 | System.out.println(findWays(4, 2, 1)); 40 | System.out.println(findWays(2, 2, 3)); 41 | System.out.println(findWays(6, 3, 8)); 42 | System.out.println(findWays(4, 2, 5)); 43 | System.out.println(findWays(4, 3, 5)); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Programming/Java/Container With Most Water/containerWithMostWater.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.*; 3 | 4 | public class containerWithMostWater 5 | { 6 | 7 | // method to calculate area of container with max water 8 | public static int calculateArea(int[] arr, int n) 9 | { 10 | int left = 0; // co-ordinate of left wall 11 | int right = n-1; // co-ordinate of right wall 12 | int maxArea=0; // store of area of conatainer with max water 13 | 14 | // lopoing till left wall crosses right wall 15 | while(left < right) 16 | { 17 | 18 | // height of container will be height of smaller wall 19 | // base length will be how far they are apart i.e., right - left 20 | 21 | int area = Math.min(arr[left],arr[right])*(right-left); 22 | 23 | 24 | // storing the max calculated area of container 25 | maxArea = Math.max(maxArea, area); 26 | 27 | // moving towards right to find left wall of higher height 28 | if(arr[left] < arr[right]) 29 | left++; 30 | 31 | // moving towards left to find right wall of higher height 32 | else 33 | right--; 34 | 35 | } 36 | return maxArea; 37 | } 38 | 39 | // driver program 40 | public static void main(String[] args) 41 | { 42 | Scanner sc = new Scanner (System.in); 43 | 44 | int n = sc.nextInt(); // number of walls 45 | int arr[] = new int[n]; // for storing height of walls 46 | 47 | for(int i = 0;i < n; i++) 48 | arr[i] = sc.nextInt(); // input height of walls 49 | 50 | 51 | System.out.println(calculateArea(arr, n)); 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Programming/C++/Tries/Memory Efficient trie implementation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | We only store the nodes here that are in the trie not the null nodes which are not required. 3 | For doing this we use map. 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | #define int long long 9 | #define pb push_back 10 | #define inf 1e9 11 | #define mod 1000000007 12 | #define ff first 13 | #define ss second 14 | 15 | struct trie 16 | { 17 | unordered_map m1; 18 | bool isend; 19 | trie() 20 | { 21 | isend = false; 22 | } 23 | }; 24 | struct trie *root; 25 | 26 | void insert(string str) 27 | { 28 | struct trie *curr = root; 29 | for (char ch : str) 30 | { 31 | if (!curr->m1.count(ch)) 32 | { 33 | curr->m1[ch] = new trie(); 34 | } 35 | curr = curr->m1[ch]; 36 | } 37 | curr->isend = true; 38 | } 39 | 40 | bool search(string str) 41 | { 42 | struct trie *curr = root; 43 | for (char ch : str) 44 | { 45 | if (!curr->m1[ch]) 46 | { 47 | return false; 48 | } 49 | curr = curr->m1[ch]; 50 | } 51 | return curr->isend; 52 | } 53 | 54 | void solve() 55 | { 56 | int n; 57 | cin >> n; 58 | root = new trie; 59 | while (n--) 60 | { 61 | string str; 62 | cin >> str; 63 | insert(str); 64 | } 65 | int q; 66 | cin >> q; 67 | while (q--) 68 | { 69 | string str; 70 | cin >> str; 71 | if (search(str)) 72 | { 73 | cout << str << " is present" << "\n"; 74 | } 75 | else 76 | { 77 | cout << str << " is not present" << "\n"; 78 | } 79 | } 80 | } 81 | 82 | signed main() 83 | { 84 | ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 85 | solve(); 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /Programming/Java/RotateKLeftKRight/RotateKLeftKRight.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class RotateKLeftKRight { 5 | 6 | static int[] rotateRight(int[] arr,int k) { 7 | int[] ans = arr; 8 | ans = reverse(ans,0,ans.length-1); 9 | ans = reverse(ans,0,k-1); 10 | ans = reverse(ans,k,ans.length-1); 11 | return ans; 12 | } 13 | 14 | static int[] rotateLeft(int[] arr,int k) { 15 | int[] ans = arr; 16 | ans = reverse(ans,0,ans.length-1); 17 | ans = reverse(ans,0,ans.length-k-1); 18 | ans = reverse(ans,ans.length-k,ans.length-1); 19 | return ans; 20 | } 21 | 22 | static int[] reverse(int[] arr,int start,int end) { 23 | while (start <= end ) { 24 | int temp = arr[start]; 25 | arr[start] = arr[end]; 26 | arr[end] = temp; 27 | start++; 28 | end--; 29 | } 30 | return arr; 31 | } 32 | 33 | public static void main(String[] args) { 34 | // TODO Auto-generated method stub 35 | Scanner s = new Scanner(System.in); 36 | int n = s.nextInt(); 37 | int[] arr = new int[n]; 38 | for(int i = 0;i < n;i++) { 39 | arr[i] = s.nextInt(); 40 | } 41 | int k = s.nextInt(); 42 | int[] leftRotate = rotateLeft(Arrays.copyOf(arr, n),k); 43 | System.out.print("Left Rotated array by K=" + k+ " times :"); 44 | for(int i = 0;i < n;i++) { 45 | System.out.print(leftRotate[i] + " "); 46 | } 47 | 48 | System.out.println(); 49 | 50 | int[] rightRotate = rotateRight(Arrays.copyOf(arr, n),k); 51 | System.out.print("Right Rotated array by K=" + k+ " times :"); 52 | for(int i = 0;i < n;i++) { 53 | System.out.print(rightRotate[i] + " "); 54 | } 55 | 56 | 57 | } 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Programming/C/Median of Two Sorted Arrays/medianoftwosortedarrays.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int m,n,i,j,temp; 7 | printf("Enter the size of the first array:"); 8 | scanf("%d",&m); 9 | printf("Enter the size of the second array:"); 10 | scanf("%d",&n); 11 | int num1[m]; 12 | int num2[n]; 13 | //Reading array elements 14 | for(i=0;imerged_array[j]){ 35 | temp=merged_array[i]; 36 | merged_array[i]=merged_array[j]; 37 | merged_array[j]=temp; 38 | } 39 | } 40 | } 41 | //Finding median 42 | float median; 43 | int middle; 44 | if(mergedarraysize == 1){ 45 | if(m == 1) 46 | median=num1[0]; 47 | else 48 | median=num2[0]; 49 | }else if(mergedarraysize%2==0){ 50 | middle=mergedarraysize/2; 51 | median=(merged_array[middle-1]+(float)merged_array[middle])/2; 52 | }else{ 53 | middle=mergedarraysize/2; 54 | median=merged_array[middle]; 55 | } 56 | printf("Median:%.5f",median); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Programming/Python/RotateArrayKTimes/rotate_array.py: -------------------------------------------------------------------------------- 1 | # Code to rotate a given array k times to the left 2 | # and to the right and return both results. 3 | 4 | def rotate_array(arr: [int], k: int) -> ([int], [int]): 5 | """Function to rotate the given array k times 6 | to both sides and return both results. 7 | 8 | :param [int] arr: Array to rotate. 9 | :param int k: Number of times to rotate the array, on both directions. 10 | :return: A tuple with the rotated arrays to the left and to the right. 11 | """ 12 | 13 | # We check if k is greater than the total length so the following mutations 14 | # can be done. We need it to be smaller than the array length. 15 | if k >= len(arr): 16 | k %= len(arr) 17 | 18 | if k == 0: 19 | # If k equals 0 means that k was a multiple of the array length, thus no 20 | # mutation needs to be applied as the result would be the array itself. 21 | return arr, arr 22 | 23 | # To rotate to the right we take the k positions on 24 | # the back and put them in front of the others. 25 | array_to_right = arr[-k:] + arr[:-k] 26 | # To rotate to the left we take the k positions 27 | # on the front and append them to the others. 28 | array_to_left = arr[k:] + arr[:k] 29 | 30 | return array_to_left, array_to_right 31 | 32 | 33 | if __name__ == "__main__": 34 | array = [1, 2, 3, 4, 5] 35 | k = 4 36 | l, r = rotate_array(array, k) 37 | print(l, r) 38 | # [5, 1, 2, 3, 4] [2, 3, 4, 5, 1] 39 | 40 | array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 41 | k = 4 42 | l, r = rotate_array(array, k) 43 | print(l, r) 44 | # [4, 5, 6, 7, 8, 9, 0, 1, 2, 3] [6, 7, 8, 9, 0, 1, 2, 3, 4, 5] 45 | -------------------------------------------------------------------------------- /Programming/Java/container_with_most_water/ContainerWithMostWater.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * A JAVA code for the question "Container With Most Water" 5 | */ 6 | 7 | public class ContainerWithMostWater { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | 12 | System.out.println("Enter the length of the array: "); 13 | int n = sc.nextInt(); 14 | 15 | int[] arr = new int[n]; 16 | 17 | System.out.println("Enter the values of the array: "); 18 | for(int i = 0; i < n; i++){ 19 | arr[i] = sc.nextInt(); //Input the heights of the lines one by one 20 | } 21 | 22 | //Will use two indicators, one from left, one from right. 23 | int left = 0; //Left indicator initiated as the first index value of the array 24 | int right = arr.length - 1; //Right indicator initiated as the last index value of the array 25 | int varArea; //Variable Area 26 | int resArea = 0; //Result Area 27 | 28 | //Calculation of the Result area 29 | while(left <= right){ 30 | varArea = (right - left) * Math.min(arr[left], arr[right]); //Check for all the maximum area possible in the container 31 | resArea = Math.max(varArea, resArea); //Assigning the maximum value in resArea 32 | 33 | //sliding the indicator left or right 34 | if(arr[left] <= arr[right]){ 35 | left++; 36 | }else{ 37 | right--; 38 | } 39 | } 40 | 41 | System.out.println("The container will contain atmost "+resArea+" unit of water."); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Programming/JavaScript/Luhn/luhnAlogorithm.js: -------------------------------------------------------------------------------- 1 | /*Implementation of the Luhn Algorithm used to validate 2 | a variety of identification numbers 3 | such as credit card numbers 4 | IMEI numbers, National Provider Identifier numbers etc. 5 | */ 6 | 7 | function luhnCheck(num) { 8 | var inputNum = num.toString(); 9 | var sum = 0; 10 | var doubleUp = false; 11 | 12 | /* from the right to left, double every other digit starting with the second to last digit.*/ 13 | for (var i = inputNum.length - 1; i >= 0; i--) { 14 | var curDigit = parseInt(inputNum.charAt(i)); 15 | 16 | /* double every other digit starting with the second to last digit */ 17 | if (doubleUp) { 18 | /* doubled number is greater than 9 than subtracted 9 */ 19 | if (curDigit * 2 > 9) { 20 | sum += curDigit * 2 - 9; 21 | } else { 22 | sum += curDigit * 2; 23 | } 24 | } else { 25 | sum += curDigit; 26 | } 27 | var doubleUp = !doubleUp; 28 | } 29 | 30 | /* sum and divide it by 10. If the remainder equals zero, the original credit card number is valid. */ 31 | return sum % 10 == 0 ? true : false; 32 | } 33 | 34 | // This is a simple vanilla test suit i made to ensure that luhnCheck is work 35 | // in order to run this suit use NodeJs on your CLI as below: 36 | // node luhnALogorithm.js 37 | testObj = { 38 | test1: luhnCheck("8675309") ? "PASS" : "FAILED", //Invalid number. Expcected False 39 | test2: luhnCheck("912030") ? "PASS" : "FAILED", // Valid number .Expected True 40 | test3: luhnCheck("829633842010") ? "PASS" : "FAILED", // Valid number .Expected True 41 | test4: luhnCheck("24859215489621") ? "PASS" : "FAILED", // Invalid number .Expected False 42 | }; 43 | console.table(testObj); 44 | -------------------------------------------------------------------------------- /Programming/Python/ReverseDoublyLinkedList/ReverseDoublyLinkedList.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | # Program to inplement reversal of a Doubly LinkedList. 4 | 5 | import math 6 | import os 7 | import random 8 | import re 9 | import sys 10 | 11 | class DoublyLinkedListNode: 12 | def __init__(self, node_data): 13 | self.data = node_data 14 | self.next = None 15 | self.prev = None 16 | 17 | class DoublyLinkedList: 18 | def __init__(self): 19 | self.head = None 20 | self.tail = None 21 | 22 | def insert_node(self, node_data): 23 | node = DoublyLinkedListNode(node_data) 24 | 25 | if not self.head: 26 | self.head = node 27 | else: 28 | self.tail.next = node 29 | node.prev = self.tail 30 | 31 | 32 | self.tail = node 33 | 34 | def print_doubly_linked_list(node, sep): 35 | while node: 36 | print(str(node.data), end=' ') 37 | node = node.next 38 | 39 | 40 | # DoublyLinkedListNode: 41 | # int data 42 | # DoublyLinkedListNode next 43 | # DoublyLinkedListNode prev 44 | 45 | def reverse(head): 46 | r = head 47 | p = None 48 | while r!=None: 49 | q = r.next 50 | r.next = p 51 | r.prev = q 52 | p = r 53 | r = q 54 | return p 55 | 56 | 57 | if __name__ == '__main__': 58 | t = int(input()) 59 | 60 | for t_itr in range(t): 61 | llist_count = int(input()) 62 | 63 | llist = DoublyLinkedList() 64 | 65 | for _ in range(llist_count): 66 | llist_item = int(input()) 67 | llist.insert_node(llist_item) 68 | 69 | llist1 = reverse(llist.head) 70 | 71 | print_doubly_linked_list(llist1, ' ') 72 | 73 | -------------------------------------------------------------------------------- /Programming/Java/MinimumPartitionProblem/MinimumPartitionProblem.java: -------------------------------------------------------------------------------- 1 | // JAVA code to partition a set into two subsets 2 | // such that the difference of subset sums 3 | // is minimum 4 | 5 | public class MinimumPartitionProblem { 6 | 7 | // Function to find the minimum sum 8 | public static int findMinRec(int arr[], int i, 9 | int sumCalculated, 10 | int sumTotal) 11 | { 12 | // If we have reached last element. 13 | // Sum of one subset is sumCalculated, 14 | // sum of other subset is sumTotal- 15 | // sumCalculated. Return absolute 16 | // difference of two sums. 17 | if (i == 0) 18 | return Math.abs((sumTotal-sumCalculated) - 19 | sumCalculated); 20 | 21 | 22 | // For every item arr[i], we have two choices 23 | // (1) We do not include it first set 24 | // (2) We include it in first set 25 | // We return minimum of two choices 26 | return Math.min(findMinRec(arr, i - 1, sumCalculated 27 | + arr[i-1], sumTotal), 28 | findMinRec(arr, i-1, 29 | sumCalculated, sumTotal)); 30 | } 31 | 32 | // Returns minimum possible difference between 33 | // sums of two subsets 34 | public static int findMin(int arr[], int n) 35 | { 36 | // Compute total sum of elements 37 | int sumTotal = 0; 38 | for (int i = 0; i < n; i++) 39 | sumTotal += arr[i]; 40 | 41 | // Compute result using recursive function 42 | return findMinRec(arr, n, 0, sumTotal); 43 | } 44 | 45 | /* Driver program to test above function */ 46 | public static void main(String[] args) 47 | { 48 | int arr[] = {3, 1, 4, 2, 2, 1}; 49 | int n = arr.length; 50 | System.out.print("The minimum difference"+ 51 | " between two sets is " + 52 | findMin(arr, n)); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Programming/C++/SortedLinkedList/SortedLinkedList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | class Node{ 6 | public: 7 | int data; 8 | Node *next; 9 | }; 10 | 11 | 12 | void sortedInsert(Node **head_ref, Node *new_node) 13 | { 14 | Node *current; 15 | //Special case for the head end 16 | 17 | if(*head_ref == NULL || (*head_ref)->data>= new_node->data) 18 | { 19 | new_node->next = *head_ref; 20 | *head_ref = new_node; 21 | } 22 | else 23 | { 24 | //Locate the node before the point of insertion 25 | 26 | current = *head_ref; 27 | while(current->next!=NULL && current->next->datadata) 28 | { 29 | current = current->next; 30 | } 31 | new_node->next = current->next; 32 | current->next = new_node; 33 | } 34 | 35 | } 36 | 37 | //create a new node 38 | 39 | Node *newNode(int new_data) 40 | { 41 | Node *new_node = new Node(); 42 | 43 | new_node->data = new_data; 44 | new_node->next = NULL; 45 | 46 | return new_node; 47 | 48 | } 49 | 50 | 51 | void printList(Node *head) 52 | { 53 | Node *temp = head; 54 | while(temp!=NULL) 55 | { 56 | cout<data<<" "; 57 | temp= temp->next; 58 | } 59 | } 60 | 61 | 62 | int main() 63 | { 64 | Node *head = NULL; 65 | Node *new_node = newNode(5); 66 | sortedInsert(&head, new_node); 67 | new_node = newNode(10); 68 | sortedInsert(&head, new_node); 69 | new_node = newNode(7); 70 | sortedInsert(&head, new_node); 71 | new_node = newNode(4); 72 | sortedInsert(&head, new_node); 73 | new_node = newNode(2); 74 | sortedInsert(&head, new_node); 75 | new_node = newNode(11); 76 | 77 | sortedInsert(&head, new_node); 78 | cout<<"Created Linked list\n"; 79 | printList(head); 80 | 81 | 82 | return 0; 83 | 84 | } 85 | -------------------------------------------------------------------------------- /Programming/C#/IntegerToRoman/IntegerToRoman.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IntegerToRoman 6 | { 7 | public class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | Console.WriteLine("Enter an integer number:"); 12 | var number = Console.ReadLine(); 13 | Console.WriteLine($"Roman number is: {IntegerToRoman(number)}"); 14 | 15 | Console.ReadLine(); 16 | } 17 | 18 | private static string IntegerToRoman(string number) 19 | { 20 | return IntegerToRoman(int.Parse(number)); 21 | } 22 | 23 | private static string IntegerToRoman(int number) 24 | { 25 | var lookUpMap = new Dictionary 26 | { 27 | { 1000, "M" }, 28 | { 900, "CM" }, 29 | { 500, "D" }, 30 | { 400, "CD" }, 31 | { 100, "C" }, 32 | { 90, "XC" }, 33 | { 50, "L" }, 34 | { 40, "XL" }, 35 | { 10, "X" }, 36 | { 9, "IX" }, 37 | { 5, "V"}, 38 | { 4, "IV" }, 39 | { 1, "I" }, 40 | }; 41 | var sb = new StringBuilder(); 42 | var test = number; 43 | 44 | while (test > 0) 45 | { 46 | foreach (var num in lookUpMap) 47 | { 48 | if (test >= num.Key) 49 | { 50 | sb.Append(num.Value); 51 | test -= num.Key; 52 | break; 53 | } 54 | } 55 | } 56 | 57 | return sb.ToString(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Programming/Java/GoldMineProblem/Gold_Mine_Problem.java: -------------------------------------------------------------------------------- 1 | // Java program to solve Gold Mine problem 2 | import java.util.Arrays; 3 | 4 | class GoldMine { 5 | 6 | static final int MAX = 100; 7 | 8 | // Returns maximum amount of gold that 9 | // can be collected when journey started 10 | // from first column and moves allowed 11 | // are right, right-up and right-down 12 | static int getMaxGold(int gold[][], int m, int n) 13 | { 14 | int goldTable[][] = new int[m][n]; 15 | 16 | for(int[] rows:goldTable) 17 | Arrays.fill(rows, 0); 18 | 19 | for (int col = n-1; col >= 0; col--) 20 | { 21 | for (int row = 0; row < m; row++) 22 | { 23 | 24 | // Gold collected on going to the cell on the right 25 | int right = (col == n-1) ? 0: goldTable[row][col+1]; 26 | 27 | // Gold collected on going to the cell to right up 28 | int right_up = (row == 0 || col == n-1) ? 0 :goldTable[row-1][col+1]; 29 | 30 | // Gold collected on going to the cell to right down 31 | int right_down = (row == m-1|| col == n-1) ? 0 :goldTable[row+1][col+1]; 32 | 33 | // Max gold collected from taking either of the above 3 paths 34 | goldTable[row][col] = gold[row][col]+ Math.max(right, Math.max(right_up,right_down)); 35 | 36 | } 37 | } 38 | 39 | // The max amount of gold collected will be 40 | // the max value in first column of all rows 41 | int res = goldTable[0][0]; 42 | 43 | for (int i = 1; i < m; i++) 44 | res = Math.max(res, goldTable[i][0]); 45 | 46 | return res; 47 | } 48 | 49 | //driver code 50 | public static void main(String arg[]) 51 | { 52 | int gold[][]= { {1, 6, 0, 8}, 53 | {3, 2, 4, 1}, 54 | {9, 0, 2, 3}, 55 | {0, 6, 1, 2} }; 56 | 57 | int m = 4, n = 4; 58 | 59 | System.out.print(getMaxGold(gold, m, n)); 60 | } 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /Programming/Python/LinkedList/LinkedList.py: -------------------------------------------------------------------------------- 1 | class Element(object): 2 | def __init__(self, value): 3 | self.value = value 4 | self.next = None 5 | 6 | class LinkedList(object): 7 | def __init__(self, head=None): 8 | self.head = head 9 | 10 | def append(self, new_element): 11 | current = self.head 12 | if self.head: 13 | while current.next: 14 | current = current.next 15 | current.next = new_element 16 | else: 17 | self.head = new_element 18 | 19 | def get_position(self, position): 20 | counter = 1 21 | current = self.head 22 | if position < 1: 23 | return None 24 | while current and counter <= position: 25 | if counter == position: 26 | return current 27 | current = current.next 28 | counter += 1 29 | return None 30 | 31 | def insert(self, new_element, position): 32 | counter = 1 33 | current = self.head 34 | if position > 1: 35 | while current and counter < position: 36 | if counter == position - 1: 37 | new_element.next = current.next 38 | current.next = new_element 39 | current = current.next 40 | counter += 1 41 | elif position == 1: 42 | new_element.next = self.head 43 | self.head = new_element 44 | 45 | def delete(self, value): 46 | current = self.head 47 | previous = None 48 | while current.value != value and current.next: 49 | previous = current 50 | current = current.next 51 | if current.value == value: 52 | if previous: 53 | previous.next = current.next 54 | else: 55 | self.head = current.next 56 | -------------------------------------------------------------------------------- /Programming/Java/Luhn'sAlgorithm/README.md: -------------------------------------------------------------------------------- 1 | # **Luhn's Algorithm** 2 | 3 | > This is an algorithm that checks whether the given **credit card** is valid or not as well as displays it belongs to which company.
4 | > That is whether it belongs to **MASTERCARD**, **VISA**, **AMERICAN EXPRESS**.
5 | 6 | ### NOTE : 7 | #### For the mentioned cards it will check their first digits as well as the total no. of digits that are mentioned below : 8 | 9 |
10 | - MASTERCARD
11 |   * First Digits  = 51, 52, 53, 54, 55. 
12 |   * No. of digits = 16
13 |   
14 | - AMERICAN EXPRESS          
15 |   * First Digits  = 34 or 37.
16 |   * No. of digits = 15
17 |   
18 | - VISA                               
19 |   * First Digits  = 4.
20 |   * No. of digits = 13 or 16
21 | 
22 | 23 | #### For the main part find whether checksum % 10 is "0" or not ? 24 |
25 | - Inorder to calculate checksum we have to do two things
26 |   
27 |   1. Multiply the even no. of digits starting from the rear-end till front-end.
28 |     * E.g: 123456 = 5*2 + 3*2 + 1*2 = 10 + 6 + 2.
29 |     * Also if any product is 2-digit no. then we have to split them add them.
30 |     * i.e : 5 * 2  = 10  which would be written as 1 + 0 + 6 + 2 = 9.
31 |     
32 |   2. Add the digits that are not multiplied by 2 starting from rear-end till front-end.
33 |     * E.g: 6 + 4 + 2 = 12.
34 |   
35 |   3. Lastly add both sum of even and odd no. of digits which we calculated earlier.
36 |     * E.g checksum = odd + even = 9 + 12 = 21.
37 | 
38 | 
39 | 40 | #### Very Last step is to check whether the checksum divided by 10 would give us remainder "0" or not ? 41 | 42 | > If so then the credit no. is valid and needs to verify its length and if it's also valid then woo-hoo :tada: you have a valid credit card.
43 | 44 | > Else if it doesn't which means you have an invalid card :stuck_out_tongue:.
45 | 46 | > In our example 21 % 10 = 1. which means our credit card is not valid. 47 | -------------------------------------------------------------------------------- /Programming/Java/Maximum Gap/MaximumGap.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.Scanner; 3 | public class Main 4 | { 5 | public static void main(String[] args) { 6 | Scanner s=new Scanner(System.in); 7 | System.out.println("Size of array"); 8 | int n=s.nextInt(); 9 | if(n<2){ 10 | System.out.println("Output: "+0); 11 | System.exit(0); 12 | } 13 | int[] arr=new int[n]; 14 | int[] diff_arr=new int[n]; 15 | int max_diff=Integer.MIN_VALUE; 16 | System.out.println("Enter array elements: "); 17 | for(int i=0;imax_diff){ 26 | max_diff=diff_arr[i]; 27 | } 28 | } 29 | 30 | System.out.println("Output: "+max_diff); 31 | 32 | } 33 | static class QuickSort 34 | { 35 | 36 | int partition(int arr[], int low, int high) 37 | { 38 | int pivot = arr[high]; 39 | int i = (low-1); 40 | for (int j=low; j