├── .vscode └── settings.json ├── ArrayWavePrint └── ColumnWise │ └── CPP │ └── ArrayWavePrint(COLUMN_WISE).C++ ├── BFS └── CPP │ └── BFS.cpp ├── BankersAlgorithm └── C │ └── BankersAlgorithm.c ├── Bellman-Ford └── Bellman Ford.cpp ├── BinarySearchInDart ├── BinarySearchTree ├── C++ │ ├── BinarySearchAlgorithm.cpp │ └── OptimalBinarySearchTreeUsingDP.c++ ├── C │ └── BinarySearchTree.c ├── Java │ └── BinarySearchTree.java └── python │ └── BinarySearchTree.py ├── BinomialHeapImplementation └── C │ └── binomialheap.c ├── Bitwise └── CPP │ └── UniqueNumberBitwise .c++ ├── C++ Stl problem ├── FindThePoint.cpp ├── Question 2.md ├── Question.md ├── solution 2.cpp ├── solution.cpp └── usingcomparators_stl.cpp ├── Codechef └── CPP │ ├── Codechef_CPP_COLE2020_DooffiresBrackets_CLBRKT.cpp │ ├── Div2_August_2020 │ ├── CHEFWARS.cpp │ ├── CHEFWED.cpp │ ├── CRDGAME3.cpp │ ├── LINCHESS.cpp │ ├── SKMP.cpp │ └── problem_links.md │ ├── Div2_July_2020 │ ├── ADAKING.cpp │ ├── CHEFNSWAPS.cpp │ ├── CHEFSTR1.cpp │ ├── CRDGAME.cpp │ ├── DRCHEF.cpp │ ├── PTMSSNG.cpp │ └── problem_links.md │ ├── Div2_June_2020 │ ├── CHEFICRM.cpp │ ├── EOEO.cpp │ ├── EVENM.cpp │ ├── PRICECON.cpp │ ├── XYSTR.cpp │ └── problem_links.md │ ├── Div2_May_cookoff_2020 │ ├── CHEFRECP.cpp │ ├── CHEFSHIP.CPP │ ├── CHEFSQUD.cpp │ ├── CHFIMPRS.cpp │ ├── CROADS.cpp │ └── problem_links.md │ ├── Div2_May_lunchtime2020 │ ├── CHEFZRON.cpp │ ├── CONVSTR.cpp │ ├── LOSTWKND.cpp │ ├── TREDIFF.cpp │ ├── WWALK.cpp │ └── problem_links.md │ ├── Div2_October_cookoff_2020 │ ├── Decreasing_Srrnmieeda.cpp │ ├── Path_etic_Sums.cpp │ ├── Split_the_Str_Ing.cpp │ └── Yet_Another_Crossover_Episode.cpp │ ├── Div2_September_2020 │ ├── ADAMAT_September.cpp │ ├── CHFNSWAP_September.cpp │ ├── COVID19B_September.cpp │ ├── CRDGAME2_September.cpp │ ├── EQDIV_September.cpp │ ├── FINXOR_September.cpp │ ├── MOVCOIN2_September.cpp │ ├── ROTATPOL_September.cpp │ ├── TREE2_September.cpp │ ├── VBR_September.cpp │ └── problem_links.md │ └── Div2_September_cookoff_2020 │ ├── BOWLERS.cpp │ ├── BULBS.CPP │ ├── MININS.cpp │ ├── MVAL.cpp │ └── problem_links.md ├── Codeforces └── CPP │ ├── 653 │ └── E1ReadingBooks.cpp │ ├── 665 div_2 │ ├── A.cpp │ └── problem_links.md │ ├── 666 div_2 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── problem_links.md │ ├── 671 div_2 │ ├── A_Digit_Game.cpp │ ├── B_Stairs.cpp │ ├── C_Killjoy.cpp │ ├── D1_Sage_s_Birthday_easy_version_.cpp │ ├── D2_Sage_s_Birthday_hard_version_.cpp │ └── problem_links.md │ ├── 672 div_2 │ ├── A_Cubes_Sorting.cpp │ ├── B_Rock_and_Lever.cpp │ ├── C1_Pok_mon_Army_easy_version_.cpp │ └── problem_links.md │ ├── 674 div_3 │ ├── A.cpp │ ├── B.cpp │ └── problem_links.md │ ├── Codeforces Round #110 (Div. 2) │ ├── B.cpp │ └── E.cpp │ ├── Codeforces Round #207 (Div. 1) │ └── B.cpp │ ├── Codeforces_667_Div3 │ ├── A.cpp │ └── B.cpp │ ├── Contest_name │ └── Watermelon.c++ │ ├── Educational Codeforces Round 23 │ ├── A.cpp │ ├── B.cpp │ └── E.cpp │ ├── Round #667 DIv. 3 │ └── Yet Another Array Restoration.cpp │ ├── School Team Contest #2 (Winter Computer School 2010 │ └── E.cpp │ └── grankforce │ ├── A_Circle_Coloring.cpp │ ├── B_Arrays_Sum.cpp │ ├── C_Discrete_Acceleration.cpp │ ├── D_Searchlights.cpp │ └── problem_links.md ├── ConvertBinaryNumbertoOctalAndVice-versa └── C++ │ └── BinaryToOctalVice-versa.C++.cpp ├── CountingDivisors └── CPP │ └── CountingDivisors.cpp ├── DFS └── CPP │ └── DFS.cpp ├── DSU on Trees └── CPP │ └── DSU on Trees.cpp ├── DSU └── DSU.cpp ├── Dijsktra's_algo ├── Algorithm │ ├── Dijsktra's_algo.md │ └── images │ │ ├── dj1.jpg │ │ ├── dj2.jpg │ │ ├── dj3.jpg │ │ ├── dj4.jpg │ │ ├── dj5.jpg │ │ └── dj6.jpg ├── CPP │ └── dijsktra's_algo.CPP ├── java │ └── dijsktra's_algo.java ├── js │ └── dijsktra's_algo.js └── python │ └── dijsktra's_algo.py ├── DisjoinSetUnion └── CPP │ └── DSU.cpp ├── DutchFlagProblem └── CPP │ └── DutchFlagProblem.cpp ├── Dynamic Programming ├── Equal_sum_partition.cpp ├── Knapsack.cpp └── Subset Sum Problem.cpp ├── FibonacciNumbers.c ├── Fibonnaci_Number_using_Matrix_Exponentiation └── C++ │ └── Fibonacci.cpp ├── FindMissingNumber └── CPP │ └── FindMissingNumber.C++ ├── FrontEndWebsite ├── Animated (Landing)Home Page │ ├── LICENSE │ ├── README.md │ ├── index.html │ └── main.css ├── Card Website Project 1 │ ├── .DS_Store │ ├── README.md │ ├── assets │ │ ├── .DS_Store │ │ ├── css │ │ │ └── main.css │ │ └── icofont │ │ │ ├── .DS_Store │ │ │ ├── fonts │ │ │ ├── .DS_Store │ │ │ ├── icofont.eot │ │ │ ├── icofont.svg │ │ │ ├── icofont.ttf │ │ │ ├── icofont.woff │ │ │ └── icofont.woff2 │ │ │ └── icofont.min.css │ ├── img │ │ └── felipe-marmol-wh7ftWYLMa8-unsplash.jpg │ └── index.html ├── Card Website Project 2 │ ├── README.md │ ├── assets │ │ ├── css │ │ │ └── main.css │ │ └── icofont │ │ │ ├── fonts │ │ │ ├── icofont.eot │ │ │ ├── icofont.svg │ │ │ ├── icofont.ttf │ │ │ ├── icofont.woff │ │ │ └── icofont.woff2 │ │ │ └── icofont.min.css │ ├── img │ │ ├── chester-wade-msnyz9L6gs4-unsplash.jpg │ │ └── felipe-marmol-wh7ftWYLMa8-unsplash.jpg │ └── index.html ├── Card Website Project 3 │ ├── .DS_Store │ ├── README.md │ ├── assets │ │ ├── .DS_Store │ │ ├── css │ │ │ └── main.css │ │ └── icofont │ │ │ ├── .DS_Store │ │ │ ├── fonts │ │ │ ├── .DS_Store │ │ │ ├── icofont.eot │ │ │ ├── icofont.svg │ │ │ ├── icofont.ttf │ │ │ ├── icofont.woff │ │ │ └── icofont.woff2 │ │ │ └── icofont.min.css │ ├── img │ │ ├── .DS_Store │ │ └── chester-wade-msnyz9L6gs4-unsplash.jpg │ └── index.html ├── Tap Music │ ├── README.md │ ├── app.js │ ├── index.html │ ├── sounds │ │ ├── bubbles.mp3 │ │ ├── clay.mp3 │ │ ├── confetti.mp3 │ │ ├── glimmer.mp3 │ │ ├── moon.mp3 │ │ └── ufo.mp3 │ └── style.css └── TeamMemberWebsite │ ├── FrontEndWebsite │ └── Drum_Kit │ │ ├── Bass-Drum.mp3 │ │ ├── crash.mp3 │ │ ├── crash.png │ │ ├── index.html │ │ ├── index.js │ │ ├── kick-bass.mp3 │ │ ├── kick.png │ │ ├── readme.md │ │ ├── snare.mp3 │ │ ├── snare.png │ │ ├── styles.css │ │ ├── tom-1.mp3 │ │ ├── tom-2.mp3 │ │ ├── tom-3.mp3 │ │ ├── tom-4.mp3 │ │ ├── tom1.png │ │ ├── tom2.png │ │ ├── tom3.png │ │ └── tom4.png │ └── team │ ├── .vscode │ └── settings.json │ ├── 3.jpg │ ├── Imortant Note.txt │ ├── README.md │ ├── images.jpg │ ├── index.html │ ├── team-3.jpg │ ├── team-4.jpg │ ├── team-5.jpg │ └── team-6.jpg ├── GoGradeProgram └── grade.go ├── Graph Problem └── CPP │ ├── AllTestCases.md │ ├── Constraints.md │ ├── Kahn.cpp │ ├── Qus(Religious People).md │ ├── code.c++ │ ├── explanation&Hint.md │ └── sample input&output.md ├── Graph-Algo-Using-C ├── 01.Graph_using_adjacency_matrix.c ├── 02.Graph_using_adjacency_list.c ├── 03.Graph_DFS.c ├── 04.Graph_BFS.c ├── 05.Kruskal.c ├── 06.prims.c └── Readme.md ├── Graphs └── C++ │ └── KosarajusAlgorithm.cpp ├── GuessNumberGame └── guess.c ├── Hangman game.py ├── HouseRobber └── CPP │ └── HouseRobber.cpp ├── Imakshat47_binary2DecimalBasic.cpp ├── Imakshat47_binary2DecimalUsingInBuildFun.cpp ├── Imakshat47_binary2DecimalUsingString.cpp ├── Imakshat47_binary2Octal.cpp ├── Imakshat47_decimal2OctalBasic.cpp ├── Imakshat47_decimal2OctalFormula.cpp ├── Imakshat47_decimal2binaryBasicArray.cpp ├── Imakshat47_decimal2binaryBasicVoid.cpp ├── Imakshat47_decimal2binaryUsingBitwise.cpp ├── Imakshat47_octal2binary.cpp ├── ImplementStrstr └── CPP │ └── ImplementFunctionStrstr.cpp ├── Interviewbit └── StackQueue │ ├── balanced_parantheses.cpp │ ├── first_non_repeating_character.cpp │ └── redundant_braces.cpp ├── InvertionCount └── CPP │ └── InvertionCount.cpp ├── Job Sequencing └── sequencing.cpp ├── KMP └── CPP │ └── KMP.cpp ├── Kadane'sAlgorithm ├── CPP │ └── Kadane'sAlgo.C++ └── Python │ └── Kadane'sAlgorithm.py ├── Krishnamurthy Number ├── Krishnamurthy_number.cpp └── readme.md ├── Kruskal's_Algorithm └── CPP │ └── kruskal_algorithm.cpp ├── LICENSE ├── Lcs └── CPP │ └── longestCommonSubsequence.cpp ├── Mad libs game.py ├── PatternProblems ├── HollowDiamondInscribedInRectanglePattern │ ├── C++ │ │ └── HollowDiamondInscribedInRectanglePattern.C++ │ ├── C │ │ └── HollowDiamondInscribedInRectanglePattern.C │ └── Java │ │ └── HollowDiamondInscribedInRectanglePattern.java └── PyramidPatternProblem │ ├── C++ │ └── PyramidPatternProblem1.cpp │ ├── C │ └── pyramidpattern1.c │ ├── JAVA │ └── PyramidPattern1.java │ └── PYTHON │ └── pyramidpattern1.py ├── Programmer's day special wish.py ├── README.md ├── Recursion └── Flood_fill_algorithm.cpp ├── RotateTheArray ├── C++ │ └── Rotate_The_Array.cpp ├── C │ └── RotateArrayByN.c ├── Java │ ├── RotateArrayGCD.java │ └── RotateTheArray.java ├── Python │ └── ArrayRotation.py ├── Swift │ └── RotateTheArray.swift └── different_array_rotations │ ├── common_sub_seq_array.cpp │ ├── left_rotation_array.cpp │ ├── rotate_2d_array.cpp │ ├── rotate_array_by_someval.cpp │ ├── spiral_array.cpp │ └── two_array_r_equal_not.cpp ├── RottenOranges └── C++ │ └── RottenOranges.C++ ├── STL-unordered_map ├── Problem.md └── freq_count.cpp ├── STL └── CPP │ ├── insert-sorted-ll.cpp │ ├── minimum_cost_of_ropes.cpp │ ├── partition in C++ STL │ ├── returnDistanceToTheNearestVowel.cpp │ ├── reverse-ll.cpp │ ├── subarray_sum.cpp │ ├── triplet_sum.cpp │ └── valid_parentheses.cpp ├── SegmentTree └── CPP │ └── SegmentTree.C++ ├── SortingAlgorithms ├── C++ │ ├── BucketSort.cpp │ ├── CountingSort.C++ │ ├── InsertionSort.CPP │ ├── SelectionSort.CPP │ ├── paritoshkray_MergeSort.cpp │ └── zahinekbal_bubbleSort_STL(Comparater-Function).C++ ├── C │ ├── Bubble_Sort.c │ ├── HeapSort.c │ ├── InsertionSort.c │ ├── Merge_Sort.c │ └── Selection_Sort.c ├── Kotlin │ └── BubbleSort.kt ├── java │ ├── BubbleSort.java │ ├── HeapSort.java │ ├── InsertionSort.java │ ├── QuickSort.java │ └── SelectionSort.java └── python │ ├── MergeSort.py │ ├── SelectionSort.py │ ├── ShellSort.py │ ├── bubbleSort.py │ ├── insertion sort.py │ └── optimiesd bubble sort.py ├── SpiralPrintArray └── CPP │ └── ArraySpiralPrint(Clockwise).c++ ├── StairCaseProblem └── C++ │ └── stair.cpp ├── StandardDeviation └── StandardDeviation.cpp ├── SubsetSum └── CPP │ └── SubsetSum.cpp ├── SumOf_n^2 └── C++ │ └── SumOf_n^2.C++ ├── SumOfcubes └── C++ │ └── SumOfcubes.C++ ├── SwappingOfNumbers └── C++ │ └── CyclicOrderUsingCallByReference.C++ ├── TowerOfHanoi ├── hanoi.py └── tower_of_hanoi.cpp ├── Vector(STL) ├── Question.md └── VectorSort.cpp ├── Z-Algorithm └── CPP │ └── Z Algorithm.cpp ├── assembly.s ├── binary2DecimalBasic.c ├── codeforces └── CPP │ └── 656 │ ├── Three-Pairwise-Maximums.cpp │ └── ThreePairwiseMaximums.cpp ├── decimal2OctalBasic.c ├── decimal2binaryBasicVoid.c ├── decimal2binaryUsingBitwise.c ├── docker └── flask │ ├── Dockerfile │ ├── app.py │ ├── docker-compose.yml │ └── requirements.txt ├── hackerrank ├── Aray │ └── 2D_array.cpp ├── FibonacciNumber.java ├── FibonacciNumbers.cpp ├── FlippingBits.cpp ├── FlippingBits.java ├── Primality.cpp ├── Primality.java ├── maps │ └── imakshat47_mapsQuery.cpp ├── sets │ └── imakshat47_stlSets.cpp ├── sort │ ├── imakshat47_complexSorting.cpp │ └── imakshat47_maxElement.cpp └── vector │ ├── imakshat47_vectorDynamicErase.cpp │ ├── imakshat47_vectorLowerBound.cpp │ └── imakshat47_vectorSort.cpp ├── img ├── Anjali.jpeg ├── AswinCG2002.jpg ├── Cuncis.jpeg ├── DeepamPriyadarshi.jpg ├── Ishika.jpg ├── Jay_Shukla.jpg ├── Kunal888.jpg ├── NishantBhatia.jpeg ├── Vishi13.jpg ├── ashfaqahmed.jpg ├── cedric-img-portrait-2.png ├── rahul.jpeg ├── rajarshi.jpg ├── sai_pranay.jpg └── zahinekbal.jpg ├── isUnique └── isUnique.cpp ├── modular-exponentiation └── modular-exponentiation.cpp ├── octal2binary.c ├── python ├── Bunny_Prisoners_plates.py ├── Checking-Prime-Number.py ├── Factorial-of-a-number-in-Python.py ├── JadooAndDNATranscription.py └── telegrambot.py └── transformation_in_2D_triangle.cpp /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "HollowDiamondInscribedInRectanglePattern.C": "cpp" 4 | } 5 | } -------------------------------------------------------------------------------- /ArrayWavePrint/ColumnWise/CPP/ArrayWavePrint(COLUMN_WISE).C++: -------------------------------------------------------------------------------- 1 | //For each column we will traverse the row in top to down or down to top direction 2 | //In case Column is Even We will traverse Top to Bottom 3 | // If the Column is Odd We will go Bottom to Top. 4 | 5 | #include 6 | using namespace std; 7 | 8 | int main(){ 9 | int a[1000][1000] = {0}; 10 | int m,n; 11 | cin>>m>>n; 12 | //Iterate over the array 13 | int val=1; 14 | for(int row=0; row<=m-1; row++){ 15 | for(int col=0; col<=n-1; col++){ 16 | a[row][col] = val; 17 | val++; 18 | cout<=0; row--){ 33 | cout< 6 | #include 7 | 8 | using namespace std; 9 | 10 | class Graph 11 | { 12 | int V; 13 | list *adj; 14 | public: 15 | Graph(int V); 16 | 17 | void addEdge(int v, int w); 18 | 19 | void BFS(int s); 20 | }; 21 | 22 | Graph::Graph(int V) 23 | { 24 | this->V = V; 25 | adj = new list[V]; 26 | } 27 | 28 | void Graph::addEdge(int v, int w) 29 | { 30 | adj[v].push_back(w); 31 | } 32 | 33 | void Graph::BFS(int s) 34 | { 35 | bool *visited = new bool[V]; 36 | for(int i = 0; i < V; i++) 37 | visited[i] = false; 38 | 39 | list queue; 40 | 41 | visited[s] = true; 42 | queue.push_back(s); 43 | 44 | list::iterator i; 45 | 46 | while(!queue.empty()) 47 | { 48 | s = queue.front(); 49 | cout << s << " "; 50 | queue.pop_front(); 51 | 52 | for (i = adj[s].begin(); i != adj[s].end(); ++i) 53 | { 54 | if (!visited[*i]) 55 | { 56 | visited[*i] = true; 57 | queue.push_back(*i); 58 | } 59 | } 60 | } 61 | } 62 | 63 | int main() 64 | { 65 | Graph g(4); 66 | g.addEdge(0, 1); 67 | g.addEdge(0, 2); 68 | g.addEdge(1, 2); 69 | g.addEdge(2, 0); 70 | g.addEdge(2, 3); 71 | g.addEdge(3, 3); 72 | 73 | cout << "Following is Breadth First Traversal " 74 | << "(starting from vertex 2) \n"; 75 | g.BFS(2); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /BinarySearchInDart: -------------------------------------------------------------------------------- 1 | void main() { 2 | List arr = [0, 1, 3, 4, 5, 8, 9, 22]; 3 | int userValue = 3; 4 | int min = 0; 5 | int max = arr.length - 1; 6 | binarySearch(arr, userValue, min, max); 7 | } 8 | 9 | binarySearch(List arr, int userValue, int min, int max) { 10 | if (max >= min) { 11 | print('min $min'); 12 | print('max $max'); 13 | int mid = ((max + min) / 2).floor(); 14 | if (userValue == arr[mid]) { 15 | print('your item is at index: ${mid}'); 16 | } else if (userValue > arr[mid]) { 17 | binarySearch(arr, userValue, mid + 1, max); 18 | } else { 19 | binarySearch(arr, userValue, min, mid - 1); 20 | } 21 | } 22 | return null; 23 | } 24 | -------------------------------------------------------------------------------- /BinarySearchTree/C++/BinarySearchAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to implement recursive Binary Search 2 | #include 3 | using namespace std; 4 | 5 | // A recursive binary search function. It returns location of x in given array arr[l..r] is present, otherwise -1 6 | 7 | int binarySearch(int arr[], int l, int r, int x) 8 | { 9 | if (r >= l) { 10 | int mid = l + (r - l) / 2; 11 | 12 | // If the element is present at the middle itself 13 | if (arr[mid] == x) 14 | return mid; 15 | 16 | // If element is smaller than mid, then it can only be present in left subarray 17 | if (arr[mid] > x) 18 | return binarySearch(arr, l, mid - 1, x); 19 | 20 | // Else the element can only be present in the right subarray 21 | return binarySearch(arr, mid + 1, r, x); 22 | } 23 | 24 | // We reach here when element is not present in array 25 | return -1; 26 | } 27 | 28 | int main(void) 29 | { 30 | int arr[] = { 2, 3, 4, 10, 40 }; 31 | int x = 10; 32 | int n = sizeof(arr) / sizeof(arr[0]); 33 | int result = binarySearch(arr, 0, n - 1, x); 34 | (result == -1) ? cout << "Element is not present in array" 35 | : cout << "Element is present at index " << result; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /BinarySearchTree/python/BinarySearchTree.py: -------------------------------------------------------------------------------- 1 | # Python Binary Search Tree program 2 | 3 | # Class that represents an individual node in a BST 4 | class Node: 5 | def __init__(self, key): 6 | self.left = None 7 | self.right = None 8 | self.val = key 9 | 10 | # function to insert a new node with the given key 11 | def insert(root, key): 12 | if root is None: 13 | return Node(key) 14 | else: 15 | if root.val == key: 16 | return root 17 | elif root.val < key: 18 | root.right = insert(root.right, key) 19 | else: 20 | root.left = insert(root.left, key) 21 | return root 22 | 23 | # function to do inorder tree traversal 24 | def inorder(root): 25 | if root: 26 | inorder(root.left) 27 | print(root.val) 28 | inorder(root.right) 29 | 30 | 31 | r = Node(50) 32 | r = insert(r, 30) 33 | r = insert(r, 20) 34 | r = insert(r, 40) 35 | r = insert(r, 70) 36 | r = insert(r, 60) 37 | r = insert(r, 80) 38 | 39 | 40 | inorder(r) 41 | -------------------------------------------------------------------------------- /Bitwise/CPP/UniqueNumberBitwise .c++: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int findSingle(int ar[], int ar_size) 6 | { 7 | 8 | int ans = ar[0]; 9 | for (int i = 1; i < ar_size; i++) 10 | ans = ans ^ ar[i]; 11 | 12 | return ans; 13 | } 14 | 15 | int main() 16 | { 17 | int sizeOfTheArray ; 18 | cout<<"Enter the total No.of numbers in list"<> sizeOfTheArray; 20 | 21 | int ar[sizeOfTheArray]; 22 | 23 | cout<<"Enter the list of numbers "<> ar[i]; 28 | } 29 | 30 | int n = sizeof(ar) / sizeof(ar[0]); 31 | cout << "Element occurring once is : " 32 | << findSingle(ar, n); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++ Stl problem/Question 2.md: -------------------------------------------------------------------------------- 1 | Initially, you have the array a consisting of one element 1 (a=[1]). 2 | 3 | In one move, you can do one of the following things: 4 | 5 | Increase some (single) element of a by 1 (choose some i from 1 to the current length of a and increase ai by one); 6 | Append the copy of some (single) element of a to the end of the array (choose some i from 1 to the current length of a and append ai to the end of the array). 7 | For example, consider the sequence of five moves: 8 | 9 | You take the first element a1, append its copy to the end of the array and get a=[1,1]. 10 | You take the first element a1, increase it by 1 and get a=[2,1]. 11 | You take the second element a2, append its copy to the end of the array and get a=[2,1,1]. 12 | You take the first element a1, append its copy to the end of the array and get a=[2,1,1,2]. 13 | You take the fourth element a4, increase it by 1 and get a=[2,1,1,3]. 14 | Your task is to find the minimum number of moves required to obtain the array with the sum at least n. 15 | 16 | You have to answer t independent test cases. 17 | 18 | Input 19 | The first line of the input contains one integer t (1≤t≤1000) — the number of test cases. Then t test cases follow. 20 | 21 | The only line of the test case contains one integer n (1≤n≤109) — the lower bound on the sum of the array. 22 | 23 | Output 24 | For each test case, print the answer: the minimum number of moves required to obtain the array with the sum at least n. 25 | 26 | -------------------------------------------------------------------------------- /C++ Stl problem/Question.md: -------------------------------------------------------------------------------- 1 | Neha and Jenish are good friends . Neha challenges Jenish to find the Highest possible Rating of given array A after applying some queries. According to Neha, Rating of an array is highest occourence of a element in the given array. Jenish is provided with the Magical Number M and Q . For Each element in the given Array A , Jenish can Perform Addition or Subtraction with M atmost Q times . 2 | 3 | Since Jenish is so confused and not able to come out with the solution , Help him to find Highest Ratings Possible for Given Array after applying queries to each element. 4 | 5 | Input : 6 | 7 | First line of Input contains integer M 8 | Second line contains integer Q 9 | Third line contains integer N 10 | Fourth line contains N elements representing elements of array A 11 | Output : 12 | 13 | Output the highest possible rating of array A after applying Queries. 14 | 15 | 16 | Constraints : 17 | 1<=N<=1000000 18 | 1<=M<=100 19 | 1<=Q<=10 20 | 1<=A(i)<=1000000 21 | -------------------------------------------------------------------------------- /C++ Stl problem/solution 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | long long int n,sum=1,count,A; 10 | 11 | cin>>n; 12 | A=(int)sqrt(n+1); 13 | count=min((n-A)/(A+1)+A,(n-A-1)/A+A-1); 14 | cout<> Mnumber >> Qtimes >> Nsize; 10 | int temp1,temp2; 11 | 12 | for (i = 0; i < Nsize; ++i) 13 | { 14 | cin >> temp1; 15 | mat[temp1]++; 16 | for (j = 1; j <= Qtimes; ++j) 17 | { 18 | temp2 = temp1 + (j*Mnumber); 19 | mat[temp2]++; 20 | temp2 = temp1 - (j*Mnumber); 21 | if(temp2>0) 22 | mat[temp2]++; 23 | } 24 | } 25 | 26 | temp2 = 0; 27 | for (i = 0; i < MAX_SIZE; ++i) 28 | { 29 | temp2 = max(temp2, mat[i]); 30 | } 31 | cout << temp2 << endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C++ Stl problem/usingcomparators_stl.cpp: -------------------------------------------------------------------------------- 1 | //program in STL CPP to sort numbers in descending order using comparators. 2 | #include 3 | using namespace std; 4 | bool compare(int a,int b) 5 | { 6 | return a>b;//to sort in decreasing order 7 | } 8 | int main(){ 9 | int n; 10 | cin>>n; 11 | int a[n]; 12 | for(int i=0;i>a[i]; 14 | sort(a,a+n,compare); 15 | //to print sorted array 16 | for(int i=0;i 2 | using namespace std; 3 | #define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define int long long 5 | #define w(x) while(x--) 6 | #define t(x) int x;cin >> x;while (x--) 7 | #define rep(d,a,n) for(auto d=a;d<=n;d++) 8 | #define rep_(d,a,n) for(auto d=a;d>=n;d--) 9 | #define nl "\n" 10 | const int mod = 1e9 + 7; 11 | const int inf = 1e18; 12 | 13 | void fun() { 14 | int n; 15 | cin >> n; 16 | char arr[8][8]; 17 | rep(i, 0, 7) { 18 | rep(j, 0, 7) { 19 | arr[i][j] = 'X'; 20 | } 21 | } 22 | arr[0][0] = 'O'; 23 | n--; 24 | rep(i, 0, 7) { 25 | rep(j, 0, 7) { 26 | if (i == 0 && j == 0) { 27 | continue; 28 | } 29 | if (n == 0) { 30 | break; 31 | } 32 | else { 33 | arr[i][j] = '.'; 34 | n--; 35 | } 36 | } 37 | } 38 | rep(i, 0, 7) { 39 | rep(j, 0, 7) { 40 | cout << arr[i][j]; 41 | } cout << nl; 42 | } cout << nl; 43 | } 44 | 45 | int32_t main() 46 | { 47 | fast_io; 48 | t(a) { 49 | fun(); 50 | } 51 | return 0; 52 | } -------------------------------------------------------------------------------- /Codechef/CPP/Div2_July_2020/CHEFSTR1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | #define rep_(d,a,n) for(int d=a;d>=n;d--) 7 | #define nl "\n" 8 | #define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 9 | #define oj freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); 10 | const int inf=1e18; 11 | 12 | void fun(){ 13 | int n; 14 | cin>>n; 15 | int *arr=new int[n]; 16 | int ans=0; 17 | rep(i,0,n-1){ 18 | cin>>arr[i]; 19 | if(i){ 20 | ans+=(abs(arr[i]-arr[i-1])-1); 21 | } 22 | } 23 | cout< 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | #define rep_(d,a,n) for(int d=a;d>=n;d--) 7 | #define nl "\n" 8 | #define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 9 | #define oj freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); 10 | const int inf=1e18; 11 | 12 | void fun(){ 13 | int n; 14 | cin>>n; 15 | int chefu=0,chomu=0; 16 | rep(i,0,n-1){ 17 | int num1,num2,sume=0,sumi=0;cin>>num1>>num2; 18 | while(num1!=0){ 19 | sume+=num1%10; 20 | num1/=10; 21 | } 22 | while(num2!=0){ 23 | sumi+=num2%10; 24 | num2/=10; 25 | } 26 | if(sume>sumi){ 27 | chefu++; 28 | }else if(sumi>sume){ 29 | chomu++; 30 | }else{ 31 | chomu++; 32 | chefu++; 33 | } 34 | } 35 | if(chefu>chomu){ 36 | cout<<0<<" "< 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | #define rep_(d,a,n) for(int d=a;d>=n;d--) 7 | #define nl "\n" 8 | #define mk(arr,n,type) type *arr=new type[n]; 9 | const int inf=1e18; 10 | const int mod=1e9+7; 11 | void print(vector ptr,int n){ 12 | rep(i,0,n-1){ 13 | cout<>n>>x; 26 | vectorarr(n); 27 | rep(i,0,n-1){ 28 | cin>>arr[i]; 29 | } 30 | sort(arr.begin(),arr.end()); 31 | if(arr[n-1]<=x){cout<=arr[i]){ 43 | break; 44 | }else{ 45 | x*=2; 46 | day++; 47 | } 48 | } 49 | x=2*arr[i]; 50 | arr[i]=0; 51 | day++; 52 | } 53 | i++; 54 | } 55 | 56 | cout< 2 | using namespace std; 3 | #define ll long long int 4 | void fun(){ 5 | ll n; 6 | cin>>n; 7 | unordered_setx; 8 | unordered_sety; 9 | ll ni=4*n-1; 10 | while(ni--){ 11 | ll x1,y1; 12 | cin>>x1>>y1; 13 | if(x.count(x1)){ 14 | x.erase(x1); 15 | }else{ 16 | x.insert(x1); 17 | } 18 | if(y.count(y1)){ 19 | y.erase(y1); 20 | }else{ 21 | y.insert(y1); 22 | } 23 | } 24 | auto itr=x.begin(); 25 | auto itr2=y.begin(); 26 | cout<<(*itr)<<" "<<(*itr2)<>t; 33 | while(t--){ 34 | fun(); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Codechef/CPP/Div2_July_2020/problem_links.md: -------------------------------------------------------------------------------- 1 | # Codechef Div_2 July Long challenge 2020 2 | Problem link of [ADAKING](https://www.codechef.com/JULY20B/problems/ADAKING/). 3 | 4 | Problem link of [CHEFNSWAPS](https://www.codechef.com/JULY20B/problems/CHEFNSWAPS/). 5 | 6 | Problem link of [CRDGAME](https://www.codechef.com/JULY20B/problems/CRDGAME/). 7 | 8 | Problem link of [DRCHEF](https://www.codechef.com/JULY20B/problems/DRCHEF/). 9 | 10 | Problem link of [CHEFSTR1](https://www.codechef.com/JULY20B/problems/CHEFSTR1/). 11 | 12 | Problem link of [PTMSSNG](https://www.codechef.com/JULY20B/problems/PTMSSNG/). -------------------------------------------------------------------------------- /Codechef/CPP/Div2_June_2020/CHEFICRM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | const int inf=1e18; 7 | void oj() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cin.tie(0); 11 | cout.tie(0); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | #endif 16 | return; 17 | } 18 | bool ans(int n,int arr[]){ 19 | vectorrs_5; 20 | vectorrs_10; 21 | vectorrs_15; 22 | rep(i,0,n-1){ 23 | if(arr[i]==5){ 24 | rs_5.push_back(5); 25 | }if(arr[i]==10){ 26 | if(rs_5.size()==0){ 27 | return false; 28 | }else{ 29 | rs_5.pop_back(); 30 | rs_10.push_back(10); 31 | } 32 | }if(arr[i]==15){ 33 | if(rs_10.size()!=0){ 34 | rs_10.pop_back(); 35 | rs_15.push_back(15); 36 | }else if(rs_5.size()>=2){ 37 | rs_5.pop_back(); 38 | rs_5.pop_back(); 39 | rs_15.push_back(15); 40 | }else{ 41 | return false; 42 | } 43 | } 44 | } 45 | return true; 46 | } 47 | int32_t main() 48 | { 49 | //oj(); 50 | w(t){ 51 | int n; 52 | cin>>n; 53 | int arr[n]; 54 | rep(i,0,n-1){ 55 | cin>>arr[i]; 56 | } 57 | if(ans(n,arr)){ 58 | cout<<"YES\n"; 59 | }else{ 60 | cout<<"NO\n"; 61 | } 62 | } 63 | return 0; 64 | } -------------------------------------------------------------------------------- /Codechef/CPP/Div2_June_2020/EOEO.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | const int inf=1e18; 7 | void oj() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cin.tie(0); 11 | cout.tie(0); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | #endif 16 | return; 17 | } 18 | int ans(int tom){ 19 | int vss=tom; 20 | if(tom%2!=0){ 21 | return (tom-1)/2; 22 | }else{ 23 | int step=1; 24 | while(tom%2==0){ 25 | tom/=2; 26 | step++; 27 | } 28 | if(tom==1){ 29 | return 0; 30 | }else{ 31 | return vss/((int)pow(2,step)); 32 | } 33 | } 34 | } 35 | int32_t main() 36 | { 37 | //oj(); 38 | w(t){ 39 | int n; 40 | cin>>n; 41 | int answer=ans(n); 42 | cout< 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | const int inf=1e18; 7 | void oj() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cin.tie(0); 11 | cout.tie(0); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | #endif 16 | return; 17 | } 18 | 19 | void ans(int n){ 20 | int arr[n][n]={}; 21 | int num=1; 22 | for(int i=0;i=0;k--){ 31 | arr[i][k]=num; 32 | num++; 33 | } 34 | } 35 | } 36 | rep(i,0,n-1){ 37 | rep(j,0,n-1){ 38 | cout<>n; 50 | ans(n); 51 | } 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Codechef/CPP/Div2_June_2020/PRICECON.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | const int inf=1e18; 7 | void oj() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cin.tie(0); 11 | cout.tie(0); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | #endif 16 | return; 17 | } 18 | 19 | int32_t main() 20 | { 21 | //oj(); 22 | w(t){ 23 | int n,k; 24 | cin>>n>>k; 25 | int arr[n];int ans=0; 26 | rep(i,0,n-1){ 27 | cin>>arr[i]; 28 | if(arr[i]>k){ 29 | ans+=(arr[i]-k); 30 | } 31 | } 32 | cout< 2 | using namespace std; 3 | #define int long long 4 | #define w(x) int x;cin >> x;while (x--) 5 | #define rep(d,a,n) for(int d=a;d<=n;d++) 6 | const int inf=1e18; 7 | void oj() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cin.tie(0); 11 | cout.tie(0); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | #endif 16 | return; 17 | } 18 | 19 | int32_t main() 20 | { 21 | //oj(); 22 | w(t){ 23 | string s1; 24 | cin>>s1; 25 | int len=s1.length(); 26 | int i=0;int ans=0; 27 | while(i<=len-2){ 28 | if(s1[i]=='x' && s1[i+1]=='y'){ 29 | ans++; 30 | i+=2; 31 | } 32 | else if(s1[i]=='y' && s1[i+1]=='x'){ 33 | ans++; 34 | i+=2; 35 | } 36 | else{ 37 | i++; 38 | } 39 | } 40 | cout< 2 | using namespace std; 3 | 4 | // int ans; 5 | int check(int start, string& str,int flag) 6 | { 7 | if((str.size()-start)%2==1) 8 | return -1; 9 | if(flag==1) 10 | { 11 | string s1 = str.substr(start,(str.size()-start)/2); 12 | string s2 = str.substr(start+(str.size()-start)/2,(str.size()-start)/2); 13 | if(s1.size()==0 || s1.compare(s2)!=0) 14 | return -1; 15 | else 16 | return 1; 17 | } 18 | int ans=0; 19 | string s1=""; 20 | for(int i=start;i0 && s1.size()==(str.size()-start)/2) 40 | return 1; 41 | } 42 | } 43 | return (ans!=0)?ans:-1; 44 | } 45 | 46 | int main() { 47 | int n; 48 | cin>>n; 49 | for(int p=1;p<=n;p++) 50 | { 51 | string str; 52 | // ans=0; 53 | cin>>str; 54 | int y=check(0,str,0); 55 | if(y!=-1) 56 | { 57 | if(p!=n) 58 | cout< 2 | using namespace std; 3 | 4 | //#define ll long long 5 | 6 | const int N = 2e5+100; 7 | double eps=1e-6; 8 | 9 | int main(){ 10 | int t; 11 | cin>>t; 12 | while(t--){ 13 | long long int n; 14 | cin>>n; 15 | //n=1000000000; 16 | long long lpg=log2(n); 17 | long long p=pow(2,lpg); 18 | if(p==n && p!=1)cout<<-1< 14 | 15 | -------------------------------------------------------------------------------- /Codechef/CPP/Div2_May_lunchtime2020/LOSTWKND.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define w(x) long long x;cin>>x;while(x--) 4 | 5 | 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cin.tie(0); 11 | cout.tie(0); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | #endif 16 | 17 | w(x) 18 | { 19 | 20 | long long arr[5], p; 21 | for (long long i = 0; i < 5; i++) 22 | cin >> arr[i]; 23 | cin >> p; 24 | long long sum = 0; 25 | 26 | 27 | for (long long i = 0; i < 5; i++) 28 | sum += arr[i]; 29 | 30 | 31 | 32 | if (sum * p <= 120) 33 | cout << "No" << endl; 34 | else 35 | cout << "Yes" << endl; 36 | 37 | 38 | 39 | } 40 | 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Codechef/CPP/Div2_May_lunchtime2020/WWALK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | inline void scan(int &x) 6 | { 7 | x = 0; 8 | bool neg = 0; 9 | register int c = getchar_unlocked(); 10 | if (c == '-') 11 | neg = 1, c = getchar_unlocked(); 12 | while ((c < 48) || (c > 57)) 13 | c = getchar(); 14 | for ( ; c < 48||c > 57 ; c = getchar_unlocked()); 15 | for ( ; c > 47 && c < 58; c = getchar_unlocked() ) 16 | x= (x << 3) + ( x << 1 ) + ( c & 15 ); 17 | if (neg) x *= -1; 18 | } 19 | 20 | int32_t main() { 21 | //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 22 | int T; 23 | cin>>T; 24 | while(T--){ 25 | int N; 26 | //cin>>N; 27 | scan(N); 28 | int alice[N]; 29 | int bob[N]; 30 | for(int i =0;i>alice[i]; 32 | scan(alice[i]); 33 | } 34 | for(int i =0;i>bob[i]; 36 | scan(bob[i]); 37 | } 38 | int ad=0,bd=0,wd=0; 39 | for(int i =0;i 3 | 4 | Problem link of [Lost Weekends](https://www.codechef.com/LTIME84B/problems/LOSTWKND/). 5 | 6 | Problem link of [Weird Walk](https://www.codechef.com/LTIME84B/problems/WWALK/). 7 | 8 | Problem link of [Convert the String](https://www.codechef.com/LTIME84B/problems/CONVSTR/). 9 | 10 | Problem link of [Tree difference](https://www.codechef.com/LTIME84B/problems/TREDIFF/). 11 | 12 | Problem link of [Escape One](https://www.codechef.com/LTIME84B/problems/CHEFZRON/).
13 | 14 | -------------------------------------------------------------------------------- /Codechef/CPP/Div2_September_2020/ADAMAT_September.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define pb push_back 4 | #define eb emplace_back 5 | #define mp make_pair 6 | #define Fast_IO ios::sync_with_stdio(false); 7 | #define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__) 8 | //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); 9 | #define fir first 10 | #define sec second 11 | #define mod 998244353 12 | #define ll long long 13 | #define inf 0x3f3f3f3f 14 | #define INF 0x3f3f3f3f3f3f3f3f 15 | inline int read() 16 | { 17 | char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();} 18 | int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();} 19 | if(nega==-1) return -ans; 20 | return ans; 21 | } 22 | typedef pair pii; 23 | #define N 70 24 | int a[N][N],n; 25 | int getid(int x,int y){return (x-1)*n+y;} 26 | void flip(int l) 27 | { 28 | for(int i=1;i<=l;i++) 29 | { 30 | for(int j=1;j>n; 36 | for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=read(); 37 | int ans=0; 38 | for(int i=n;i>=1;i--) 39 | { 40 | bool ok=1; 41 | for(int j=1;j<=i;j++) if(a[i][j]!=getid(i,j)) ok=0; 42 | for(int j=1;j<=i;j++) if(a[j][i]!=getid(j,i)) ok=0; 43 | if(!ok) ans++,flip(i); 44 | } 45 | cout< 2 | using namespace std; 3 | void fastscan(long long &num) 4 | { 5 | num=0; 6 | int c; 7 | c=getchar_unlocked(); 8 | for(;c>47&&c<58;c=getchar_unlocked()) 9 | { 10 | num=num*10+c-48; 11 | } 12 | return; 13 | } 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(false); 17 | cin.tie(NULL); 18 | long long t; 19 | fastscan(t); 20 | for(int i=0;id) 45 | ct+=d; 46 | else 47 | ct+=n-b; 48 | for(int j=b;j>=1;j--) 49 | { 50 | s=s+j; 51 | if(s=n) break; 53 | } 54 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int t, b, answer; 9 | 10 | cin >> t; 11 | 12 | long long int arr[21]; 13 | arr[0] = 1; 14 | 15 | for (int i = 1; i < 21; i++) 16 | arr[i] = 2 * arr[i - 1]; 17 | 18 | while (t--) 19 | { 20 | long long int n, s, summ, summm, final; 21 | cin >> n; 22 | cout << 1 << " " << arr[20] << endl; 23 | cout.flush(); 24 | cin >> s; 25 | s -= arr[20] * n; 26 | final = 0; 27 | if (s % 2 != 0) 28 | final++; 29 | for (int i = 1; i < 20; i++) 30 | { 31 | summ = s + (arr[i] * n); 32 | cout << 1 << " " << arr[i] << endl; 33 | cout.flush(); 34 | cin >> summm; 35 | if (((summ - summm) / (arr[i] * 2)) % 2 != 0) 36 | final += arr[i]; 37 | } 38 | cout << 2 << " " << final << endl; 39 | cout.flush(); 40 | 41 | cin >> answer; 42 | 43 | if (answer == -1) 44 | break; 45 | } 46 | } -------------------------------------------------------------------------------- /Codechef/CPP/Div2_September_2020/TREE2_September.cpp: -------------------------------------------------------------------------------- 1 | #if 1 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | char getinput() 18 | { 19 | char in[] = "3 3 1 2 3 3 1 1 1"; 20 | static int i = 0; 21 | return in[i++]; 22 | } 23 | 24 | typedef unsigned long long int ULL; 25 | typedef long long int LL; 26 | 27 | #ifndef ONLINE_JUDGE 28 | #define gchar getinput() 29 | #else 30 | #define gchar getchar_unlocked() 31 | #endif 32 | 33 | 34 | int fastread() 35 | { 36 | register char c = 0; 37 | while (c < 33) 38 | c = gchar; 39 | 40 | int sign = 1; 41 | if (c == '-') 42 | { 43 | sign = -1; 44 | c = gchar; 45 | } 46 | int a = 0; 47 | while (c > 33) 48 | { 49 | a = a * 10 + c - '0'; 50 | c = gchar; 51 | } 52 | a *= sign; 53 | return a; 54 | } 55 | 56 | 57 | int a[100002]; 58 | int main(int argc, char* argv[]) 59 | { 60 | int t, n, i, c; 61 | t = fastread(); 62 | while (t--) 63 | { 64 | n = fastread(); 65 | for (i = 0; i < n; ++i) 66 | { 67 | a[i] = fastread(); 68 | } 69 | 70 | sort(a, a + n); 71 | 72 | i = 0; 73 | while ((i < n) && (a[i] == 0)) 74 | { 75 | ++i; 76 | } 77 | 78 | if (i == n) 79 | { 80 | printf("0\n"); 81 | continue; 82 | } 83 | 84 | c = 1; 85 | for (i = i+1; i < n; ++i) 86 | { 87 | if (a[i - 1] != a[i]) 88 | { 89 | ++c; 90 | } 91 | } 92 | printf("%d\n", c); 93 | } 94 | 95 | return 0; 96 | } 97 | 98 | #endif -------------------------------------------------------------------------------- /Codechef/CPP/Div2_September_2020/problem_links.md: -------------------------------------------------------------------------------- 1 | # Codechef Div_2 September Long challenge 2020 2 | Problem link of [ADAMAT](https://www.codechef.com/SEPT20B/problems/ADAMAT/). 3 | 4 | Problem link of [CHEFNSWAP](https://www.codechef.com/SEPT20B/problems/CHEFNSWAP/). 5 | 6 | Problem link of [COVID19B](https://www.codechef.com/SEPT20B/problems/COVID19B/). 7 | 8 | Problem link of [CRDGAME2](https://www.codechef.com/SEPT20B/problems/CRDGAME2/). 9 | 10 | Problem link of [EQDIV](https://www.codechef.com/SEPT20B/problems/EQDIV/). 11 | 12 | Problem link of [FINXOR](https://www.codechef.com/SEPT20B/problems/FINXOR/). 13 | 14 | Problem link of [MOVCOIN2](https://www.codechef.com/SEPT20B/problems/MOVCOIN2/). 15 | 16 | Problem link of [ROTAPOL](https://www.codechef.com/SEPT20B/problems/ROTAPOL/). 17 | 18 | Problem link of [TREE2](https://www.codechef.com/SEPT20B/problems/TREE2/). 19 | 20 | Problem link of [VBR](https://www.codechef.com/SEPT20B/problems/VBR/). -------------------------------------------------------------------------------- /Codechef/CPP/Div2_September_cookoff_2020/BOWLERS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n,k,l,c=0,c1=0; 9 | cin>>n>>k>>l; 10 | if(n==1) 11 | cout<<"1\n"; 12 | else if(k==1||k*l 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n,k=0,ch_size=1,s=0; 9 | cin>>n; 10 | int a[n]; 11 | vector temp; 12 | for(int i=0;i>a[i]; 14 | if(i==0||__gcd(a[i],a[i-1])==1) 15 | { 16 | temp.push_back(1); 17 | k++; 18 | } 19 | else 20 | temp[k-1]++; 21 | } 22 | int fl=0; 23 | if(k>1&&__gcd(a[0],a[n-1])>1) 24 | { 25 | temp[0]+=temp.back(); 26 | temp.pop_back(); 27 | } 28 | if(k==1&&__gcd(a[0],a[n-1])>1) 29 | fl=1; 30 | 31 | vector ans(n+1,0); 32 | for(auto var:temp){ 33 | for(float i=2;i<=var;i++){ 34 | if(fl) 35 | ans[i]+=ceil(var/(i-1)); 36 | else 37 | ans[i]+=ceil(var/(i-1))-1; 38 | } 39 | } 40 | for(int i=2;i<=n;i++) 41 | cout< 2 | #define int long long 3 | using namespace std; 4 | 5 | 6 | int32_t main() { 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n],sum=0,l=0,r=n-1,cnt=0; 13 | for(int i=0;i>a[i]; 15 | if(a[i]>=0) 16 | sum=sum+a[i]; 17 | else 18 | cnt++; 19 | } 20 | cout< v1,v2; 26 | 27 | while(l < r) { 28 | while(l < n && a[l] < 0) 29 | l++; 30 | 31 | while(r >= 0 && a[r] > 0) 32 | r--; 33 | 34 | if(l < r) { 35 | v1.push_back(l); 36 | v2.push_back(r); 37 | l++; 38 | r--; 39 | } 40 | } 41 | int k=v1.size()+v2.size(); 42 | reverse(v2.begin(), v2.end()); 43 | cout< 12 | 13 | -------------------------------------------------------------------------------- /Codeforces/CPP/665 div_2/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print_arr(vector&arr){ 5 | for(auto i:arr) 6 | cout< reheap(vectorarray,int val,int n){ 11 | int left=-1; 12 | int right=-1; 13 | if(val*2<=n){ 14 | left=val*2; 15 | } 16 | else 17 | return array; 18 | if((val*2+1)<=n){ 19 | right=val*2+1; 20 | } 21 | int temp; 22 | if(right==-1) 23 | temp=left; 24 | else 25 | temp=(array[left]>=array[right])?left:right; 26 | if(array[temp]>array[n]){ 27 | int t=array[temp]; 28 | array[temp]=array[n]; 29 | array[n]=t; 30 | reheap(array,val-1,n); 31 | } 32 | return array; 33 | } 34 | 35 | void heapsort(vector&array_1,int n){ 36 | int count=1; 37 | for(int i=n/2;i>=0;i--){ 38 | array_1=reheap(array_1,i,n-1); 39 | int t=array_1[0]; 40 | array_1[0]=array_1[n-count]; 41 | array_1[n-count]=t; 42 | count++; 43 | print_arr(array_1); 44 | } 45 | print_arr(array_1); 46 | } 47 | int main(){ 48 | int n; 49 | cout<<"Enter Total Number:\n"; 50 | cin>>n; 51 | vectorarr(n); 52 | for(int i=0;i>arr[i]; 54 | // heapsort(arr,n); 55 | return 0; 56 | } -------------------------------------------------------------------------------- /Codeforces/CPP/665 div_2/problem_links.md: -------------------------------------------------------------------------------- 1 | # Codeforces div-2 665 2 | Problem link of [A](https://codeforces.com/contest/1401/problem/A/). 3 | -------------------------------------------------------------------------------- /Codeforces/CPP/666 div_2/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define author "Sihare0riginals" 4 | #define ss string 5 | #define lli long long int 6 | #define ld long double 7 | #define f first 8 | #define s second 9 | #define all(v) v.begin(),v.end() 10 | #define I(a,i) memset(a,i,sizeof(a)); 11 | #define pb push_back 12 | #define mp make_pair 13 | #define L(i,start,end) for(lli i=start;i<=end;i++) 14 | #define R(i,start,end) for(lli i=start;i>=end;i--) 15 | #define ip(n) cin>>n;lli ip[n+1];L(i,1,n)cin>>ip[i]; 16 | const lli LINF = 1e18,mod=1e9+7; 17 | void Bl0ck_M0mb0(); 18 | 19 | 20 | signed main() 21 | { 22 | Bl0ck_M0mb0(); 23 | lli t=1; 24 | //cin>>t; 25 | while(t--){ 26 | lli n; 27 | cin>>n; 28 | lli a[n+1]; 29 | L(i,1,n) 30 | cin>>a[i]; 31 | if(n==1) //If single element subtract it since len=1 is multiple of -val 32 | { 33 | cout<<"1 1\n"<<-a[1]<<"\n"; 34 | cout<<"1 1\n0\n1 1\n0\n"; 35 | } 36 | else //If Length >1 make all elements except last multiple of n by adding val*(n-1) 37 | { 38 | cout<<"1 "< 2 | using namespace std; 3 | int main(){ 4 | 5 | 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n,x; 10 | cin>>n>>x; 11 | if(n<=2) 12 | cout<<"1"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m; 8 | cin>>n>>m; 9 | int a[4],c=0; 10 | for(int i=0;i>a[0]>>a[1]>>a[2]>>a[3]; 12 | if(a[1]==a[2]) 13 | c=1; 14 | } 15 | if(m%2) 16 | cout<<"NO"< 2 | using namespace std; 3 | #define LL long long 4 | #define PI 3.14159265358979323 5 | 6 | int main() 7 | { 8 | int n, j = 0; 9 | cin>>n; 10 | int arr[n]; 11 | double sum = 0; 12 | 13 | for (int i = 0;i < n; i++) { 14 | cin>>arr[i]; 15 | } 16 | 17 | sort(arr, arr + n); 18 | for (int i = n - 1; i >= 0; i--) 19 | { 20 | if(!(j%2))sum += arr[i] * arr[i] * PI; 21 | else sum -= arr[i] * arr[i] * PI; 22 | j++; 23 | } 24 | cout << fixed << setprecision(10) << sum; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/CPP/Codeforces Round #110 (Div. 2)/E.cpp: -------------------------------------------------------------------------------- 1 | // Tags: DP, Math 2 | 3 | #include 4 | #define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) 5 | #define ll long long 6 | #define f first 7 | #define s second 8 | using namespace std; 9 | 10 | const int N = 105, M = 2505, mod = 1e9 + 7; 11 | 12 | int t, n, m, dp[N][M]; 13 | string s; 14 | 15 | int sum() 16 | { 17 | int ret = 0; 18 | for(auto i : s) 19 | ret += i - 'a' + 1; 20 | return ret; 21 | } 22 | 23 | int solve(int i, int sm) 24 | { 25 | if(i == 0) 26 | return (sm == 0); 27 | int &x = dp[i][sm]; 28 | if(x != -1) 29 | return x; 30 | x = 0; 31 | for(int j = 1; j <= min(sm, 26); j++) 32 | x = (x + solve(i - 1, sm - j)) % mod; 33 | return x; 34 | } 35 | 36 | int main() 37 | { 38 | IO; 39 | memset(dp, -1, sizeof dp); 40 | cin >> t; 41 | while(t--) 42 | { 43 | cin >> s; 44 | n = s.size(); 45 | m = sum(); 46 | cout << (solve(n, m) - 1 + mod) % mod << '\n'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Codeforces/CPP/Codeforces Round #207 (Div. 1)/B.cpp: -------------------------------------------------------------------------------- 1 | // Tags: Implementation, Math 2 | 3 | #include 4 | #define LL long long 5 | using namespace std; 6 | int aa[26][1000050], bb[26][1000050]; 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cout.tie(0); 11 | cin.tie(0); 12 | LL n, m; 13 | cin >> n >> m; 14 | string a, b; 15 | cin >> a >> b; 16 | LL g = __gcd(a.size(), b.size()); 17 | LL l = a.size() * (b.size() / g), sz = a.size() * n, ans = 0; 18 | for (int i = 0; i < a.size(); i++) 19 | aa[a[i] - 'a'][i % g]++; 20 | for (int i = 0; i < b.size(); i++) 21 | bb[b[i] - 'a'][i % g]++; 22 | for (int i = 0; i < g; i++) 23 | for (int j = 0; j < 26; j++) 24 | ans += (LL)aa[j][i] * (LL)bb[j][i]; 25 | ans *= (sz / l); 26 | cout << sz - ans; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Codeforces/CPP/Contest_name/Watermelon.c++: -------------------------------------------------------------------------------- 1 | //Question 2 | /* 3 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. 4 | 5 | Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. 6 | 7 | Input 8 | The first (and the only) input line contains integer number w (1?=?w?=?100) — the weight of the watermelon bought by the boys. 9 | 10 | Output 11 | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. 12 | */ 13 | 14 | //Code 15 | #include 16 | using namespace std; 17 | int main(){ 18 | int w; 19 | scanf("%d",&w); 20 | if(w%2==0&&w>3){ 21 | printf("YES"); 22 | } 23 | else{ 24 | printf("NO"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Codeforces/CPP/Educational Codeforces Round 23/A.cpp: -------------------------------------------------------------------------------- 1 | // Tags: Implementation, math, number theory 2 | 3 | #include 4 | #define LL long long 5 | using namespace std; 6 | int main() 7 | { 8 | int xi,yi,xf,yf,x,y; 9 | cin>>xi>>yi>>xf>>yf>>x>>y; 10 | bool ok=(abs(yf-yi)%y||abs(xf-xi)%x); 11 | if(ok)return puts("NO"); 12 | puts((abs(yf-yi)/y)%2==(abs(xf-xi)/x)%2?"YES":"NO"); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Codeforces/CPP/Educational Codeforces Round 23/B.cpp: -------------------------------------------------------------------------------- 1 | // Tags: Combinatorics, Implementation, Math, Sortings 2 | 3 | #include 4 | #define LL long long 5 | using namespace std; 6 | int main() 7 | { 8 | mapm; 9 | int n; cin>>n; 10 | LL ans=0,x; 11 | vectora(n),b; 12 | for(int i=0;i>a[i]; 13 | sort(a.begin(),a.end()); 14 | for(auto i:a)if(i==a[0]||i==a[1]||i==a[2])b.push_back(i),m[i]++; 15 | if(a[0]==a[1]&&a[0]==a[2]) 16 | { 17 | for(int i=0;i 4 | #define ll long long 5 | #define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) 6 | using namespace std; 7 | 8 | const int N = 2e5 + 50; 9 | 10 | string cnv(int n) 11 | { 12 | string ret; 13 | while(n) 14 | ret += (n % 2 + '0'), n /= 2; 15 | while(ret.size() < 30) 16 | ret += '0'; 17 | reverse(ret.begin(), ret.end()); 18 | return ret; 19 | } 20 | 21 | struct node 22 | { 23 | node *ch[2]; 24 | int c[2]; 25 | node() 26 | { 27 | ch[0] = ch[1] = 0; 28 | c[0] = c[1] = 0; 29 | } 30 | 31 | void Go(string &n, int sgn, int i = 0) 32 | { 33 | if(i == 30) 34 | return; 35 | int x = n[i] - '0'; 36 | if(!ch[x]) 37 | ch[x] = new node(); 38 | c[x] += sgn; 39 | ch[x]->Go(n, sgn, i + 1); 40 | } 41 | }*root; 42 | 43 | int Get(string &p, string &l) 44 | { 45 | node *cur = root; 46 | int ans = 0; 47 | for(int i = 0; i < 30; i++) 48 | { 49 | int x = p[i] - '0'; 50 | if(l[i] - '0') 51 | { 52 | ans += cur->c[x]; 53 | if(cur->c[!x]) 54 | cur = cur->ch[!x]; 55 | else 56 | return ans; 57 | } 58 | else 59 | { 60 | if(cur->c[x]) 61 | cur = cur->ch[x]; 62 | else 63 | return ans; 64 | } 65 | } 66 | return ans; 67 | } 68 | 69 | int main() 70 | { 71 | IO; 72 | root = new node(); 73 | int q, t, p, l; 74 | cin >> q; 75 | while(q--) 76 | { 77 | cin >> t >> p; 78 | string pp = cnv(p); 79 | if(t == 1) 80 | root->Go(pp, 1); 81 | else if(t == 2) 82 | root->Go(pp, -1); 83 | else 84 | { 85 | cin >> l; 86 | string L = cnv(l); 87 | cout << Get(pp, L) << '\n'; 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /Codeforces/CPP/Round #667 DIv. 3/Yet Another Array Restoration.cpp: -------------------------------------------------------------------------------- 1 | //Codeforces Round #667 Div(3) 2 | //Rating: 1200 3 | //tags: brute force, math, number theory 4 | //https://codeforces.com/contest/1409/problem/C 5 | #include 6 | 7 | #define PB push_back 8 | using namespace std; 9 | 10 | void TEST(){ 11 | int n,x,y; 12 | cin >> n >> x >> y; 13 | int dist = y-x; 14 | int dunno; 15 | for(int i = n-1; i > 0; i--){ 16 | if(dist % i == 0){ 17 | dunno = dist / i; 18 | break; 19 | } 20 | } 21 | vector ans; 22 | int add = 0; 23 | for(int i = 0; i< n; i++){ 24 | if(add == 0){ 25 | if(y-(dunno*i) <=0){ 26 | add = 2; 27 | ans.PB(y+ (dunno)); 28 | }else{ 29 | ans.PB(y-(dunno*i)); 30 | } 31 | }else{ 32 | ans.PB(y + (dunno*add)); 33 | add++; 34 | } 35 | } 36 | for(int i = 0; i< n; i++){ 37 | cout << ans[i] << " "; 38 | } 39 | } 40 | int main(){ 41 | ios_base::sync_with_stdio(0); 42 | cin.tie(0); 43 | int T; 44 | cin >> T; 45 | for(int i = 0;i < T; i++){ 46 | TEST(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Codeforces/CPP/School Team Contest #2 (Winter Computer School 2010/E.cpp: -------------------------------------------------------------------------------- 1 | // Tags: DP 2 | 3 | #include 4 | #define ll long long 5 | #define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) 6 | using namespace std; 7 | 8 | const int N = 205; 9 | 10 | int k, a, b, dp[N][N]; 11 | string s; 12 | 13 | int solve(int i, int l) 14 | { 15 | if(i == s.size()) 16 | return l == k; 17 | 18 | if(l == k) 19 | return 0; 20 | 21 | if(dp[i][l] != -1) 22 | return dp[i][l]; 23 | 24 | dp[i][l] = 0; 25 | 26 | for(int j = a; j <= b; j++) 27 | if(i + j <= s.size()) 28 | dp[i][l] |= solve(i + j, l + 1); 29 | 30 | return dp[i][l]; 31 | 32 | } 33 | 34 | void build(int i, int l) 35 | { 36 | if(i == s.size()) 37 | return; 38 | 39 | if(l == k) 40 | return; 41 | 42 | for(int j = a; j <= b; j++) 43 | { 44 | if(i + j > s.size()) 45 | break; 46 | if(!solve(i + j, l + 1)) 47 | continue; 48 | 49 | cout << s.substr(i, j) << '\n'; 50 | build(i + j, l + 1); 51 | return; 52 | } 53 | } 54 | 55 | int main() 56 | { 57 | IO; 58 | memset(dp, -1, sizeof dp); 59 | 60 | cin >> k >> a >> b >> s; 61 | 62 | if(solve(0, 0)) 63 | build(0, 0); 64 | else 65 | cout << "No solution"; 66 | 67 | } -------------------------------------------------------------------------------- /Codeforces/CPP/grankforce/problem_links.md: -------------------------------------------------------------------------------- 1 | # Codeforces GRAKNFORCE 2 | Problem link of [A](https://codeforces.com/contest/1408/problem/A). 3 | -------------------------------------------------------------------------------- /ConvertBinaryNumbertoOctalAndVice-versa/C++/BinaryToOctalVice-versa.C++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int convertBinarytoOctal(long long); 7 | int main() 8 | { 9 | long long binaryNumber; 10 | 11 | cout << "Enter a binary number: "; 12 | cin >> binaryNumber; 13 | 14 | cout << binaryNumber << " in binary = " << convertBinarytoOctal(binaryNumber) << " in octal "; 15 | 16 | return 0; 17 | } 18 | 19 | int convertBinarytoOctal(long long binaryNumber) 20 | { 21 | int octalNumber = 0, decimalNumber = 0, i = 0; 22 | 23 | while(binaryNumber != 0) 24 | { 25 | decimalNumber += (binaryNumber%10) * pow(2,i); 26 | ++i; 27 | binaryNumber/=10; 28 | } 29 | 30 | i = 1; 31 | 32 | while (decimalNumber != 0) 33 | { 34 | octalNumber += (decimalNumber % 8) * i; 35 | decimalNumber /= 8; 36 | i *= 10; 37 | } 38 | 39 | return octalNumber; 40 | } -------------------------------------------------------------------------------- /DFS/CPP/DFS.cpp: -------------------------------------------------------------------------------- 1 | // recursive implementation of DFS of an Undirected Graph in C++ 2 | 3 | #include 4 | using namespace std; 5 | // function to perform dfs... 6 | void dfs(vector v[100],int* vis,int start) 7 | { 8 | vis[start]=1; 9 | cout< v[100]; 20 | int i,j,n; 21 | cout<<"Enter the number edges present"<>n; 23 | cout<<"Enter the edges"<>i>>j; // undirected edge between i and j 27 | v[i].push_back(j); 28 | v[j].push_back(i); 29 | 30 | } 31 | int vis[n+1]; // to keep track of visited vertices 32 | for(int i=0;i<=n;i++) 33 | vis[i]=0; 34 | for(int i=0;i<=n;i++) 35 | { 36 | if(vis[i]==0) // in case having more than 1 component 37 | { 38 | dfs(v,vis,i); 39 | } 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /DSU on Trees/CPP/DSU on Trees.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | #define sc(x) scanf("%d",&x) 7 | #define INF (2e9) 8 | #define F first 9 | #define S second 10 | #define mp(x,y) make_pair(x,y) 11 | 12 | typedef long long ll; 13 | typedef pair ii; 14 | typedef vector vii; 15 | typedef vector vi; 16 | 17 | const int N = 1e6 + 20; 18 | 19 | int sz[N]; 20 | vi adj[N]; 21 | int col[N]; 22 | void pre(int u, int p) { 23 | sz[u] = 1; 24 | for (int v : adj[u]) 25 | if (v != p) { 26 | pre(v, u); 27 | sz[u] += sz[v]; 28 | } 29 | } 30 | 31 | bool big[N]; 32 | int cnt[N]; 33 | void add(int u, int p, int x) { 34 | 35 | cnt[col[u]] += x; 36 | for (int v : adj[u]) 37 | if (v != p && !big[v]) 38 | add(v, u, x); 39 | } 40 | 41 | void dfs(int u, int p, bool keep) { 42 | int mx = -1, bigChild = -1; 43 | for (int v : adj[u]) 44 | if (v != p && sz[v] > mx) 45 | mx = sz[v], bigChild = v; 46 | 47 | for (int v : adj[u]) 48 | if (v != p && v != bigChild) 49 | dfs(v, u, 0); 50 | if (bigChild != -1) 51 | dfs(bigChild, u, 1), big[bigChild] = 1; 52 | 53 | add(u, p, 1); 54 | //cnt has answer now 55 | 56 | if (bigChild != -1) 57 | big[bigChild] = 0; 58 | 59 | if (!keep) 60 | add(u, p, -1); 61 | 62 | } 63 | 64 | int main() { 65 | 66 | } 67 | -------------------------------------------------------------------------------- /DSU/DSU.cpp: -------------------------------------------------------------------------------- 1 | //Author : bhavyakala 2 | //College : Birla Institute of Technology, Mesra, Ranchi 3 | #include 4 | using namespace std; 5 | #define ll long long int 6 | #define ld long double 7 | #define fr0(i,e) for(ll i=0;i=e;i--) 10 | #define fr(i,s,e) for(ll i=s;i { 12 | if (node !== startNode) distances[node] = Infinity; 13 | prev[node] = null; 14 | }); 15 | 16 | while (!pq.isEmpty()) { 17 | let minNode = pq.dequeue(); 18 | let currNode = minNode.data; 19 | let weight = minNode.priority; 20 | this.edges[currNode].forEach(neighbor => { 21 | let alt = distances[currNode] + neighbor.weight; 22 | if (alt < distances[neighbor.node]) { 23 | distances[neighbor.node] = alt; 24 | prev[neighbor.node] = currNode; 25 | pq.enqueue(neighbor.node, distances[neighbor.node]); 26 | } 27 | }); 28 | } 29 | return distances; 30 | } 31 | 32 | let g = new Graph(); 33 | g.addNode("A"); 34 | g.addNode("B"); 35 | g.addNode("C"); 36 | g.addNode("D"); 37 | g.addNode("E"); 38 | g.addNode("F"); 39 | g.addNode("G"); 40 | 41 | g.addDirectedEdge("A", "C", 100); 42 | g.addDirectedEdge("A", "B", 3); 43 | g.addDirectedEdge("A", "D", 4); 44 | g.addDirectedEdge("D", "C", 3); 45 | g.addDirectedEdge("D", "E", 8); 46 | g.addDirectedEdge("E", "F", 10); 47 | g.addDirectedEdge("B", "G", 9); 48 | g.addDirectedEdge("E", "G", 50); 49 | 50 | console.log(g.djikstraAlgorithm("A")); 51 | -------------------------------------------------------------------------------- /DisjoinSetUnion/CPP/DSU.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define rank rnk 5 | const int N = 1e5 + 5; 6 | int rank[N], p[N]; 7 | 8 | void init() { 9 | for (int i = 0; i < N; i++) 10 | rank[i] = 0, p[i] = i; 11 | } 12 | 13 | int findp(int n) { 14 | return n == p[n] ? n : p[n] = findp(p[n]); 15 | } 16 | 17 | bool merge(int u, int v) { 18 | u = findp(u); 19 | v = findp(v); 20 | if (u == v) 21 | return false; 22 | if (rank[u] < rank[v]) 23 | swap(u, v); 24 | 25 | if (rank[u] == rank[v]) 26 | rank[u]++; 27 | 28 | p[v]=u; 29 | return true; 30 | } 31 | 32 | bool isSameSet(int u,int v){ 33 | return findp(u)==findp(v); 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /DutchFlagProblem/CPP/DutchFlagProblem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n, l, r, m; 6 | cin >> n; 7 | vector a(n, 0); 8 | for (l = 0; l < n; l++) 9 | cin >> a[l]; 10 | l = 0, r = n - 1, m = 0; 11 | 12 | while (m <= r) 13 | { 14 | if (a[m] == 0) 15 | swap(a[l++], a[m++]); 16 | else if (a[m] == 1) 17 | m++; 18 | else 19 | swap(a[m], a[r--]); 20 | } 21 | for (l = 0; l < n; l++) 22 | cout << a[l] << " "; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /FibonacciNumbers.c: -------------------------------------------------------------------------------- 1 | /* 2 | # The Fibonacci Sequence 3 | 4 | The Fibonacci sequence appears in nature all around us, in the arrangement of seeds in a sunflower and the spiral of a nautilus for example. 5 | 6 | The Fibonacci sequence begins with and as its first and second terms. After these first two elements, each subsequent element is equal to the sum of the previous two elements. 7 | 8 | Programmatically: 9 | 10 | Given , return the number in the sequence. 11 | 12 | As an example, . The Fibonacci sequence to is . With zero-based indexing, . 13 | 14 | Function Description 15 | 16 | Complete the recursive function in the editor below. It must return the element in the Fibonacci sequence. 17 | 18 | fibonacci has the following parameter(s): 19 | 20 | n: the integer index of the sequence to return 21 | Input Format 22 | The input line contains a single integer. 23 | 24 | Output Format 25 | Locked stub code in the editor prints the integer value returned by the function. 26 | 27 | Sample Input 28 | 3 29 | 30 | Sample Output 31 | 2 32 | */ 33 | #include 34 | 35 | int fibonacci(int n) 36 | { 37 | // Complete the function. 38 | if (n < 1) 39 | return 0; 40 | if (n == 1) 41 | return 1; 42 | return fibonacci(n - 1) + fibonacci(n - 2); 43 | } 44 | 45 | int main() 46 | { 47 | int n; 48 | scanf("%d", &n); 49 | printf("%d",fibonacci(n)); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Fibonnaci_Number_using_Matrix_Exponentiation/C++/Fibonacci.cpp: -------------------------------------------------------------------------------- 1 | // Finding nth Fibbonaci Number modulo 10^9+7 in O(Logn) 2 | 3 | #include 4 | using namespace std; 5 | #define rep(i,n) for(int i=0;i 0) { 23 | if (b & 1) 24 | res = res * a ; 25 | a = a * a ; 26 | b >>= 1; 27 | } 28 | return res; 29 | } 30 | int main(){ 31 | long long n; 32 | cin>>n; 33 | if(n==0){cout<<0< 2 | 3 | 4 | 5 | 6 | 7 | Your title here 8 | 9 | 13 | 17 | 18 | 19 | 20 | 31 |
32 |

33 | M 34 | Y 35 |   36 | P 37 | O 38 | R 39 | T 40 | F 41 | O 42 | L 43 | I 44 | O 45 |

46 |
47 |
48 | 53 |
54 | 55 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/README.md: -------------------------------------------------------------------------------- 1 | # Card Website Project 1 2 | 3 | Tiny website with Boostrap cards. 4 | Feel free to use it as a base for your one page projects 5 | 6 | ## Link to the demo 7 | https://pixeliz-corporation.fr/demos/onepage/card-websiteproject-1/ -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/assets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/assets/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/assets/css/main.css: -------------------------------------------------------------------------------- 1 | /* Card Website Project 1 */ 2 | 3 | :root { 4 | --linkColor: #212529; 5 | --linkColorHover: var(--color1); 6 | --shadow: #7a4b6f; 7 | --color1: rgb(148, 89, 57); 8 | --color2: rgb(185, 117, 206); 9 | --color3: rgb(152, 106, 67) 10 | } 11 | 12 | /* Global */ 13 | 14 | body { 15 | background: linear-gradient(45deg, var(--color1) , var(--color2), var(--color3)); 16 | font-family: 'Roboto', sans-serif; 17 | } 18 | 19 | a { 20 | color: var(--linkColor); 21 | } 22 | 23 | a:hover { 24 | color: var(--linkColorHover); 25 | } 26 | 27 | /* Card */ 28 | 29 | .card-container { 30 | display: flex; 31 | justify-content: center; 32 | height: 100vh; 33 | } 34 | 35 | .card-container .card { 36 | align-self: center; 37 | box-shadow: 0px 0px 30px var(--shadow); 38 | border-radius: 0; 39 | width: 20em; 40 | } 41 | 42 | .card-container .card-title { 43 | margin-bottom: 0; 44 | } 45 | 46 | .card-container .list-group-item i { 47 | margin-right: 0.3em; 48 | } 49 | 50 | .card-container .card-link i { 51 | font-size: 1.1em; 52 | } 53 | -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/assets/icofont/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/assets/icofont/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/icofont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/icofont.ttf -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/icofont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/icofont.woff -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/icofont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/assets/icofont/fonts/icofont.woff2 -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 1/img/felipe-marmol-wh7ftWYLMa8-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 1/img/felipe-marmol-wh7ftWYLMa8-unsplash.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 2/README.md: -------------------------------------------------------------------------------- 1 | # Card Website Project 2 2 | 3 | Tiny website with Boostrap cards. 4 | Feel free to use it as a base for your one page projects 5 | 6 | ## Link to the demo 7 | https://pixeliz-corporation.fr/demos/onepage/card-websiteproject-2/ -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 2/assets/css/main.css: -------------------------------------------------------------------------------- 1 | /* Card Website Project 1 */ 2 | 3 | :root { 4 | --color: #000; 5 | --linkColor: var(--color); 6 | --borderSize: 3px; 7 | --borderColor: var(--color); 8 | } 9 | 10 | /* Global */ 11 | 12 | body { 13 | color: var(--color); 14 | font-family: 'Roboto', sans-serif; 15 | } 16 | 17 | .logo { 18 | font-family: 'Syne Mono', monospace; 19 | } 20 | 21 | a { 22 | color: var(--linkColor); 23 | } 24 | 25 | a:hover { 26 | text-decoration: underline; 27 | } 28 | 29 | .bg-dark { 30 | background-color: var(--color)!important; 31 | } 32 | 33 | /* Card */ 34 | 35 | .card-img, .card-img-top { 36 | border-top-left-radius: 0; 37 | border-top-right-radius: 0; 38 | } 39 | 40 | .card { 41 | align-self: center; 42 | width: 20em; 43 | border: var(--borderSize) solid var(--borderColor); 44 | border-radius: 0; 45 | } 46 | -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 2/assets/icofont/fonts/icofont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 2/assets/icofont/fonts/icofont.ttf -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 2/assets/icofont/fonts/icofont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 2/assets/icofont/fonts/icofont.woff -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 2/assets/icofont/fonts/icofont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 2/assets/icofont/fonts/icofont.woff2 -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 2/img/chester-wade-msnyz9L6gs4-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 2/img/chester-wade-msnyz9L6gs4-unsplash.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 2/img/felipe-marmol-wh7ftWYLMa8-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 2/img/felipe-marmol-wh7ftWYLMa8-unsplash.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/README.md: -------------------------------------------------------------------------------- 1 | # Card Website Project 3 2 | 3 | Tiny website with Boostrap cards. 4 | Feel free to use it as a base for your one page projects 5 | 6 | ## Link to the demo 7 | https://pixeliz-corporation.fr/demos/onepage/card-websiteproject-3/ -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/assets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/assets/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/assets/css/main.css: -------------------------------------------------------------------------------- 1 | /* Card Website Project 1 */ 2 | 3 | :root { 4 | --linkColor: #212529; 5 | --linkColorHover: var(--color1); 6 | --shadow: #7a4b6f; 7 | --color1: rgb(148, 89, 57); 8 | --color2: rgb(185, 117, 206); 9 | --color3: rgb(152, 106, 67) 10 | } 11 | 12 | /* Global */ 13 | 14 | body { 15 | background: linear-gradient(45deg, var(--color1) , var(--color2), var(--color3)); 16 | font-family: 'Roboto', sans-serif; 17 | } 18 | 19 | a { 20 | color: var(--linkColor); 21 | } 22 | 23 | a:hover { 24 | color: var(--linkColorHover); 25 | } 26 | 27 | /* Card */ 28 | 29 | .card-container { 30 | display: flex; 31 | justify-content: center; 32 | height: 100vh; 33 | border: 20px solid #000; 34 | } 35 | 36 | .card-img, .card-img-bottom { 37 | border-bottom-right-radius: 0; 38 | border-bottom-left-radius: 0; 39 | } 40 | 41 | .card-container .card { 42 | align-self: center; 43 | box-shadow: 0px 0px 30px var(--shadow); 44 | border-radius: 0; 45 | max-width: 70%; 46 | } 47 | 48 | .card-container .list-group-item i { 49 | margin-right: 0.3em; 50 | } 51 | 52 | .card-container .card-link i { 53 | font-size: 1.1em; 54 | } 55 | -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/assets/icofont/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/assets/icofont/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/icofont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/icofont.ttf -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/icofont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/icofont.woff -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/icofont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/assets/icofont/fonts/icofont.woff2 -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/img/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/img/.DS_Store -------------------------------------------------------------------------------- /FrontEndWebsite/Card Website Project 3/img/chester-wade-msnyz9L6gs4-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Card Website Project 3/img/chester-wade-msnyz9L6gs4-unsplash.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### Link to my Website:- 3 | https://tapmusic-ash.netlify.app/ -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/app.js: -------------------------------------------------------------------------------- 1 | window.addEventListener('load', () => { 2 | const sounds = document.querySelectorAll('.sound'); 3 | const pads = document.querySelectorAll('.pads div'); 4 | const visual = document.querySelector('.visual'); 5 | const colors = [ 6 | '#60d394', 7 | '#d36060', 8 | '#c060d3', 9 | '#d3d160', 10 | '#606bd3', 11 | '#60c2d3' 12 | ]; 13 | 14 | // Lets get going with the sound her 15 | pads.forEach((pad, index) => { 16 | pad.addEventListener('click', function () { 17 | sounds[index].currentTime = 0; 18 | sounds[index].play(); 19 | 20 | createBubbles(index); 21 | }); 22 | }); 23 | 24 | // Create a function that makes bubbles 25 | const createBubbles = (index) => { 26 | const bubble = document.createElement('div'); 27 | visual.appendChild(bubble); 28 | bubble.style.backgroundColor = colors[index]; 29 | bubble.style.animation = 'jump 1s ease-in-out'; 30 | 31 | bubble.addEventListener('animationend', function () { 32 | visual.removeChild(this); 33 | }) 34 | } 35 | }) 36 | 37 | -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Tap Music 11 | 12 | 13 | 14 |
15 |
16 |

Tap Music

17 |

Make music with only one tap

18 |
19 | 20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 |
28 | 29 |
30 |
31 | 32 |
33 |
34 | 35 |
36 |
37 | 38 |
39 |
40 | 41 |
42 |
43 |
44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/sounds/bubbles.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Tap Music/sounds/bubbles.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/sounds/clay.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Tap Music/sounds/clay.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/sounds/confetti.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Tap Music/sounds/confetti.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/sounds/glimmer.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Tap Music/sounds/glimmer.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/sounds/moon.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Tap Music/sounds/moon.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/sounds/ufo.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/Tap Music/sounds/ufo.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/Tap Music/style.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | box-sizing: border-box; 5 | } 6 | 7 | body { 8 | font-family: 'Montserrat', sans-serif; 9 | } 10 | 11 | .app { 12 | height: 100vh; 13 | display: flex; 14 | flex-direction: column; 15 | justify-content: space-between; 16 | align-items: center; 17 | } 18 | 19 | header h1 { 20 | margin: 50px 0px 30px 0px; 21 | text-align: center; 22 | font-size: 40px; 23 | } 24 | 25 | header p { 26 | font-size: 20px; 27 | } 28 | 29 | .pads { 30 | background: lightblue; 31 | width: 100%; 32 | display: flex; 33 | } 34 | 35 | .pads div { 36 | height: 100px; 37 | width: 100px; 38 | flex: 1; 39 | } 40 | 41 | .pad1 { 42 | background: #60d394; 43 | } 44 | 45 | .pad2 { 46 | background: #d36060; 47 | } 48 | 49 | .pad3 { 50 | background: #c060d3; 51 | } 52 | 53 | .pad4 { 54 | background: #d3d160; 55 | } 56 | 57 | .pad5 { 58 | background: #6860d3; 59 | } 60 | 61 | .pad6 { 62 | background: #60b2d3; 63 | } 64 | 65 | @keyframes jump { 66 | 0% { 67 | bottom: 0%; 68 | left: 20%; 69 | } 70 | 50% { 71 | bottom: 50%; 72 | left: 50%; 73 | } 74 | 100% { 75 | bottom: 0%; 76 | left: 80%; 77 | } 78 | } 79 | 80 | .visual div { 81 | position: absolute; 82 | height: 50px; 83 | width: 50px; 84 | border-radius: 50%; 85 | bottom: 0%; 86 | z-index: -1; 87 | } -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/Bass-Drum.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/Bass-Drum.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/crash.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/crash.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/crash.png -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Drum Kit 7 | 8 | 9 | 10 | 11 | 12 |

Drum 🥁 Kit

13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 |
27 | Made with ❤️ by Rajvir. 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/kick-bass.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/kick-bass.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/kick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/kick.png -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is a simple project of creating a drum kit using javascript to make our webpage responsive using various javascript tools and functions along with the knowledge of the document object model. It only uses HTML , CSS and advanced javascript to create this drum kit. 4 | 5 | I have used the concept of advanced javascript involving document object model . 6 | 7 | The link to this website is : https://rajvir1602.github.io/Drums/. 8 | -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/snare.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/snare.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/snare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/snare.png -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | text-align: center; 3 | background-color: #283149; 4 | } 5 | 6 | h1 { 7 | font-size: 5rem; 8 | color: #DBEDF3; 9 | font-family: "Arvo", cursive; 10 | text-shadow: 3px 0 #DA0463; 11 | 12 | } 13 | 14 | footer { 15 | color: #DBEDF3; 16 | font-family: sans-serif; 17 | } 18 | 19 | .w { 20 | background-image: url("images/tom1.png"); 21 | } 22 | 23 | .a { 24 | background-image: url("images/tom2.png"); 25 | } 26 | 27 | .s { 28 | background-image: url("images/tom3.png"); 29 | } 30 | 31 | .d { 32 | background-image: url("images/tom4.png"); 33 | } 34 | 35 | .j { 36 | background-image: url("images/snare.png"); 37 | } 38 | 39 | .k { 40 | background-image: url("images/crash.png"); 41 | } 42 | 43 | .l { 44 | background-image: url("images/kick.png"); 45 | } 46 | 47 | .set { 48 | margin: 10% auto; 49 | } 50 | 51 | .pressed { 52 | box-shadow: 0 3px 4px 0 #DBEDF3; 53 | opacity: 0.5; 54 | } 55 | 56 | .red { 57 | color: red; 58 | } 59 | 60 | .drum { 61 | outline: none; 62 | border: 10px solid #404B69; 63 | font-size: 5rem; 64 | font-family: 'Arvo', cursive; 65 | line-height: 2; 66 | font-weight: 900; 67 | color: #DA0463; 68 | text-shadow: 3px 0 #DBEDF3; 69 | border-radius: 15px; 70 | display: inline-block; 71 | width: 150px; 72 | height: 150px; 73 | text-align: center; 74 | margin: 10px; 75 | background-color: white; 76 | } 77 | -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-1.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-2.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-3.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-4.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom-4.mp3 -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom1.png -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom2.png -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom3.png -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/FrontEndWebsite/Drum_Kit/tom4.png -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "liveServer.settings.port": 5501, 3 | "git.ignoreLimitWarning": true 4 | } -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/team/3.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/Imortant Note.txt: -------------------------------------------------------------------------------- 1 | SUPPORT ME PLEASE 2 | 3 | [[ 95% OFF JUST FOR YOU ]] 4 | 5 | 6 | Hi Beautiful People out there 7 | Hope you are doing great 8 | 9 | Here i am giving some special DISCOUNT for my BESTSELLING website Design courses for you 10 | 11 | Its Actual Price is 200 usd But i am giving to you just in 10 usd Just 95% OFF for being my YouTube Family 12 | 13 | 14 | Courses Are following 15 | 16 | #1 Website designing course 17 | 18 | https://www.udemy.com/build-a-real-world-responsive-website-with-html-5-css-3-js/?couponCode=LEARN_SOMETHING 19 | 20 | #2 Website designing course 21 | 22 | https://www.udemy.com/build-a-new-and-modern-looking-responsive-websites/?couponCode=YOU-NOW 23 | 24 | #3 All courses listed below 25 | 26 | Checkout my Bestselling courses here now - https://www.udemy.com/user/51a26aa6-9abe-4763-9c39-8909b6290c6a/ 27 | 28 | 29 | 30 | ------------------------------- 31 | 32 | Sincerely 33 | 34 | Adil Ahmed -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### Link to my Website:- 3 | https://zahinekbal.github.io/Team-Section/ -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/images.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/team/images.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/team-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/team/team-3.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/team-4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/team/team-4.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/team-5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/team/team-5.jpg -------------------------------------------------------------------------------- /FrontEndWebsite/TeamMemberWebsite/team/team-6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/FrontEndWebsite/TeamMemberWebsite/team/team-6.jpg -------------------------------------------------------------------------------- /GoGradeProgram/grade.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "log" 8 | "strconv" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | fmt.Print("Enter a grade: ") 14 | reader := bufio.NewReader(os.Stdin) 15 | input, err := reader.ReadString('\n') 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | 20 | input = strings.TrimSpace(input) 21 | grade, err := strconv.ParseFloat(input,64) 22 | if err != nil { 23 | log.Fatal(err) 24 | } 25 | 26 | fmt.Println(grade) 27 | 28 | if grade >= 60 { 29 | fmt.Println("You pass!") 30 | } else if grade < 60 { 31 | fmt.Println("You fail!") 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Graph Problem/CPP/AllTestCases.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test case 1 4 | INPUT:- 5 | 2 6 | 3 3 5 2 7 | 2 3 8 | 4 2 OUTPUT OF TEST CASE 1:- 9 | 3 4 9 10 | 7 7 3 6 21 11 | 2 4 12 | 4 5 13 | 3 5 14 | 2 3 15 | 3 4 16 | 6 7 17 | 18 | TEST CASE 2:- 19 | INPUT:- 20 | 1 21 | 6 7 2 1 OUTPUT OF TEST CASE 2:- 22 | 1 3 23 | 3 4 7 24 | 2 4 25 | 1 2 26 | 2 3 27 | 1 5 28 | 5 6 29 | 30 | TEST CASE 3:- 31 | INPUT:- 32 | 3 33 | 3 4 1 2 34 | 3 4 35 | 5 6 36 | 4 5 OUTPUT OF TEST CASE 3:- 37 | 3 6 38 | 4 4 2 2 3 39 | 3 4 8 40 | 5 6 20 41 | 4 5 42 | 3 6 43 | 4 5 5 8 44 | 3 4 45 | 5 6 46 | 4 5 47 | 3 6 48 | 4 8 49 | 50 | TEST CASE4:- 51 | INPUT:- 52 | 1 53 | 8 8 8 8 OUTPUT OF Test CASE 4:- 54 | 1 8 55 | 3 4 64 56 | 5 6 57 | 4 5 58 | 6 7 59 | 2 3 60 | 7 8 61 | 1 2 62 | 63 | TEST CASE 5:- 64 | INPUT:- 65 | 3 66 | 5 5 3 4 67 | 3 6 68 | 3 5 OUTPUT OF TEST CASE 6:- 69 | 5 6 70 | 6 7 15 71 | 9 8 15 72 | 5 5 3 4 15 73 | 3 6 74 | 3 5 75 | 5 6 76 | 6 7 77 | 3 6 78 | 5 5 3 4 79 | 3 6 80 | 3 5 81 | 5 6 82 | 9 10 83 | 1 9 84 | 85 | TEST CASE 6:- 86 | INPUT:- 87 | 3 88 | 3 3 2 1 OUTPUT FOR TEST CASE 6:- 89 | 1 2 90 | 3 1 4 91 | 2 3 12 92 | 6 6 2 5 4 93 | 1 3 94 | 3 4 95 | 2 4 96 | 1 2 97 | 2 3 98 | 5 6 99 | 4 4 6 1 100 | 1 2 101 | 2 3 102 | 5 6 103 | 9 8 104 | -------------------------------------------------------------------------------- /Graph Problem/CPP/Constraints.md: -------------------------------------------------------------------------------- 1 | 1 <= T <= 10. 2 | 1 <= N <= 100000. 3 | 0 <= M <= 100000. 4 | 1 <= A,B <= 1000000000. 5 | 1 <= U,V <= N. 6 | Each road connects 2 distinct cities. -------------------------------------------------------------------------------- /Graph Problem/CPP/Qus(Religious People).md: -------------------------------------------------------------------------------- 1 | Amritsar is the largest and most important city in punjab and is a cultural and transportation centre. 2 | It is also the centre of Sikhism and the site of the Sikh's principal place of worship-the HarmandirSahib, 3 | or Golden temple.Let us consider 4 | There are N cities in Amritsar numbered from 1 to N. 5 | Due to a storm, every road in Amritsar was destroyed and now no temples are left. 6 | There are 2 types of operations : 7 | 8 | You can construct a temple by giving away A dollars in ith city. 9 | You can repair an already existing road by giving away B dollars. 10 | 11 | Your goal is to make temples such that people of every city have access to some temple. 12 | People of the ith city can visit the temple only if : 13 | A temple exists in that city. 14 | OR 15 | There is a path from that city to a city which contains a temple. (the path should consist of repaired roads only) 16 | You have to minimize the total cost such that people in every city can go to a temple and output this minimum cost. 17 | 18 | NOTE : You can only repair the roads which existed and not build on your own. 19 | 20 | -----***Input Format**---- 21 | 22 | The first line consists of number of test cases T. 23 | Each test case consists of 4 integers 24 | N (which denote number of cities), 25 | M (number of roads which existed), 26 | A (cost to build a temple), 27 | B (cost to repair a road). 28 | Next M lines contains M pairs denoted by U V which indicates a road existed between U and V. 29 | 30 | ------****Output Format***-------- 31 | Total minimum cost in dollars. -------------------------------------------------------------------------------- /Graph Problem/CPP/explanation&Hint.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ------------:----Explanation---------------- 4 | 5 | For first test case of sample input: 6 | 7 | build temple in city 1 for 2 dollars. 8 | repair road between 1 and 2 and repair road between 2 and 3 for total cost of 1+1 dollars. 9 | hence total cost is 4 dollars. 10 | For second test case: You can build a temple in every city for a total cost of 6*2 = 12 dollars. 11 | 12 | -----------****HINT 2 ***---------------- 13 | 14 | You can either make a road or temple if cost of road is greater then temple then it is easy to make 15 | temple rather than road but if roat cost is less then temple then you need to find where temple can 16 | be make and how many different cities are connected to it 17 | for example:- 18 | 1 2 19 | 2 3 20 | 3 4 21 | 5 6 22 | temple cost is = 5 and road cost is = 2... 23 | so you can make temple in city 1 and city have path to city 1 are 2,3, and 4 so 24 | cost= 5 + 2 * 3 = 11 25 | also you have to make temple at city 5 as no path btwn city 1 and 5 but city 6 is connect to 5 26 | so cost = 5 + 2=7 27 | total = 11 + 7=18; 28 | basically you have to find component of graph.... -------------------------------------------------------------------------------- /Graph Problem/CPP/sample input&output.md: -------------------------------------------------------------------------------- 1 | Sample Input 2 | 2 3 | 3 3 2 1 4 | 1 2 5 | 3 1 6 | 2 3 7 | 6 6 2 5 8 | 1 3 9 | 3 4 10 | 2 4 11 | 1 2 12 | 2 3 13 | 5 6 14 | 15 | Sample Output 16 | 4 17 | 12 18 | 19 | 20 | -------------------------------------------------------------------------------- /Graph-Algo-Using-C/01.Graph_using_adjacency_matrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int array[100][100]; 5 | int e,n; 6 | printf("Enter no of nodes and edges: "); 7 | scanf("%d%d",&n,&e); 8 | for(int i=1;i<=n;i++) 9 | { 10 | for(int j=1;j<=n;j++) 11 | { 12 | array[i][j]=0; 13 | } 14 | } 15 | int a,b; 16 | for(int i=0;i low) 13 | { 14 | /* make a guess */ 15 | myguess = (high + low) / 2; 16 | printf("Guess #%d: Is your number higher than %d? ", 17 | guess++, myguess, high, low); 18 | 19 | /* get your response */ 20 | scanf(" %c",&reply); 21 | 22 | if (reply == 'y') 23 | low = myguess = myguess + 1; 24 | else 25 | high = myguess; 26 | } 27 | printf("Your number is %d!\n", myguess); 28 | } 29 | -------------------------------------------------------------------------------- /HouseRobber/CPP/HouseRobber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin >> n; 7 | vector nums(n, 0); 8 | vector dp(n, 0); 9 | int i; 10 | for (i = 0; i < n; i++) 11 | cin >> nums[i]; 12 | if (n == 0) 13 | cout << 0; 14 | else if (n == 1) 15 | cout << nums[0]; 16 | else if (n == 2) 17 | cout << max(nums[0], nums[1]); 18 | else 19 | { 20 | dp[0] = nums[0]; 21 | dp[1] = max(nums[0], nums[1]); 22 | for (i = 2; i < n; i++) 23 | dp[i] = max(nums[i] + dp[i - 2], dp[i - 1]); 24 | cout << dp[n - 1]; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Imakshat47_binary2DecimalBasic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Binary To Decimal Conversion 3 | 4 | Given a binary number as input, we need to write a program to convert the given binary number into an equivalent decimal number. 5 | 6 | Examples : 7 | 8 | Input : 111 9 | Output : 7 10 | 11 | Input : 1010 12 | Output : 10 13 | 14 | Input: 100001 15 | Output: 33 16 | */ 17 | #include 18 | using namespace std; 19 | 20 | int bin2dec(int num) 21 | { 22 | int dec = 0, base = 1; 23 | while (num != 0) 24 | { 25 | dec = dec + ((num % 10) * base); 26 | base *= 2; 27 | num /= 10; 28 | } 29 | return dec; 30 | } 31 | 32 | int main() 33 | { 34 | 35 | // for test case 36 | int t; 37 | scanf("%d", &t); 38 | 39 | while (t--) 40 | { 41 | // main logic 42 | int num; 43 | scanf("%d", &num); 44 | 45 | printf("%d\n", bin2dec(num)); 46 | } 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /Imakshat47_binary2DecimalUsingInBuildFun.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Binary To Decimal Conversion 3 | 4 | Given a binary number as input, we need to write a program to convert the given binary number into an equivalent decimal number. 5 | 6 | Examples : 7 | 8 | Input : 111 9 | Output : 7 10 | 11 | Input : 1010 12 | Output : 10 13 | 14 | Input: 100001 15 | Output: 33 16 | */ 17 | #include 18 | using namespace std; 19 | 20 | int main() 21 | { 22 | 23 | // for test case 24 | int t; 25 | 26 | scanf("%d\n", &t); 27 | 28 | while (t--) 29 | { 30 | // main logic 31 | char str[100001]; 32 | 33 | scanf("%s", str); 34 | 35 | printf("%d\n", stoi(str, 0, 2)); 36 | } 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Imakshat47_binary2DecimalUsingString.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Binary To Decimal Conversion 3 | 4 | Given a binary number as input, we need to write a program to convert the given binary number into an equivalent decimal number. 5 | 6 | Examples : 7 | 8 | Input : 111 9 | Output : 7 10 | 11 | Input : 1010 12 | Output : 10 13 | 14 | Input: 100001 15 | Output: 33 16 | */ 17 | #include 18 | using namespace std; 19 | 20 | int bin2dec(string num) 21 | { 22 | int dec = 0, base = 1; 23 | for (int i = num.length() - 1; i >= 0; --i) 24 | { 25 | if (num[i] == '1') 26 | dec += base; 27 | base *= 2; 28 | } 29 | return dec; 30 | } 31 | 32 | int main() 33 | { 34 | 35 | // for test case 36 | int t; 37 | 38 | scanf("%d\n", &t); 39 | 40 | while (t--) 41 | { 42 | // main logic 43 | string str; 44 | 45 | getline(cin, str); 46 | 47 | printf("%d\n", bin2dec(str)); 48 | } 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Imakshat47_binary2Octal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Binary to Octal Conversion 3 | Given a binary number as input, we need to write a program to convert the given binary number into equivalent octal number. i.e convert the number with base value 2 to base value 8. The base value of a number system determines the number of digits used to represent a numeric value. For example, the binary number system uses two digits 0 and 1, octal number system uses 8 digits from 0-7 and binary number system uses 10 digits 0-9 to represent any numeric value. 4 | 5 | Examples: 6 | 7 | Input : 10101 8 | Output : 25 9 | 10 | Input : 101001 11 | Output : 51 12 | 13 | Input: 101 14 | Output: 5 15 | */ 16 | 17 | #include 18 | using namespace std; 19 | 20 | int bin2Octal(int num) 21 | { 22 | int octal = 0, base = 1; 23 | int dec = 0, b = 1; 24 | 25 | while (num != 0) 26 | { 27 | dec += (num % 10) * b; 28 | b *= 2; 29 | num /= 10; 30 | } 31 | 32 | while (dec != 0) 33 | { 34 | octal += ((dec % 8) * base); 35 | base *= 10; 36 | dec /= 8; 37 | } 38 | 39 | return octal; 40 | } 41 | 42 | int main() 43 | { 44 | int t; 45 | scanf("%d", &t); 46 | 47 | while (t--) 48 | { 49 | int num; 50 | scanf("%d", &num); 51 | printf("%d\n", bin2Octal(num)); 52 | } 53 | 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Imakshat47_decimal2OctalBasic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Octal Conversion 3 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent octal number. i.e convert the number with base value 10 to base value 8. The base value of a number system determines the number of digits used to represent a numeric value. For example, the binary number system uses two digits 0 and 1, octal number system uses 8 digits from 0-7 and decimal number system uses 10 digits 0-9 to represent any numeric value. 4 | 5 | Examples: 6 | 7 | Input : 16 8 | Output : 20 9 | 10 | Input : 10 11 | Output : 12 12 | 13 | Input: 33 14 | Output: 41 15 | 16 | Time Complexity: O(log N) 17 | */ 18 | 19 | #include 20 | using namespace std; 21 | 22 | void dec2Octal(int num) 23 | { 24 | int octalNum[100]; 25 | 26 | int i = 0; 27 | while (num != 0) 28 | { 29 | octalNum[i++] = num % 8; 30 | num = num / 8; 31 | } 32 | 33 | for (int j = i - 1; j >= 0; j--) 34 | printf("%d", octalNum[j]); 35 | 36 | printf("\n"); 37 | } 38 | 39 | int main() 40 | { 41 | int t; 42 | scanf("%d", &t); 43 | 44 | while (t--) 45 | { 46 | int num; 47 | scanf("%d", &num); 48 | dec2Octal(num); 49 | } 50 | 51 | return 0; 52 | } -------------------------------------------------------------------------------- /Imakshat47_decimal2OctalFormula.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Octal Conversion 3 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent octal number. i.e convert the number with base value 10 to base value 8. The base value of a number system determines the number of digits used to represent a numeric value. For example, the binary number system uses two digits 0 and 1, octal number system uses 8 digits from 0-7 and decimal number system uses 10 digits 0-9 to represent any numeric value. 4 | 5 | Examples: 6 | 7 | Input : 16 8 | Output : 20 9 | 10 | Input : 10 11 | Output : 12 12 | 13 | Input: 33 14 | Output: 41 15 | 16 | Time Complexity: O(1) 17 | */ 18 | 19 | #include 20 | using namespace std; 21 | 22 | int dec2Octal(int num) 23 | { 24 | int octal = 0, base = 1; 25 | while (num != 0) 26 | { 27 | octal += ((num % 8) * base); 28 | base *= 10; 29 | num /= 8; 30 | } 31 | return octal; 32 | } 33 | 34 | int main() 35 | { 36 | int t; 37 | scanf("%d", &t); 38 | 39 | while (t--) 40 | { 41 | int num; 42 | scanf("%d", &num); 43 | printf("%d\n", dec2Octal(num)); 44 | } 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Imakshat47_decimal2binaryBasicArray.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Binary Conversion 3 | 4 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. 5 | 6 | Examples: 7 | 8 | Input : 7 9 | Output : 111 10 | 11 | Input : 10 12 | Output : 1010 13 | 14 | Input: 33 15 | Output: 100001 16 | */ 17 | #include 18 | using namespace std; 19 | 20 | int *dec2bin(int num) 21 | { 22 | int *binaryNum = new int[33]; 23 | 24 | int i = 0; 25 | 26 | while (num > 0) 27 | { 28 | binaryNum[i] = num % 2; 29 | num = num / 2; 30 | ++i; 31 | } 32 | 33 | binaryNum[32] = i - 1; 34 | 35 | return binaryNum; 36 | } 37 | 38 | int main() 39 | { 40 | int t; 41 | scanf("%d\n", &t); 42 | 43 | while (t--) 44 | { 45 | int num; 46 | scanf("%d", &num); 47 | 48 | if (num == 0) 49 | { 50 | printf("0\n"); 51 | continue; 52 | } 53 | 54 | int *res = dec2bin(num); 55 | 56 | for (int j = res[32]; j >= 0; --j) 57 | printf("%d", res[j]); 58 | 59 | printf("\n"); 60 | } 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /Imakshat47_decimal2binaryBasicVoid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Binary Conversion 3 | 4 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. 5 | 6 | Examples: 7 | 8 | Input : 7 9 | Output : 111 10 | 11 | Input : 10 12 | Output : 1010 13 | 14 | Input: 33 15 | Output: 100001 16 | */ 17 | #include 18 | using namespace std; 19 | 20 | void dec2bin(int num) 21 | { 22 | int str[32]; 23 | if (num == 0) 24 | { 25 | printf("0\n"); 26 | return; 27 | } 28 | 29 | int i = 0; 30 | 31 | while (num > 0) 32 | { 33 | str[i] = num % 2; 34 | num = num / 2; 35 | ++i; 36 | } 37 | 38 | for (int j = i - 1; j >= 0; --j) 39 | printf("%d", str[j]); 40 | 41 | printf("\n"); 42 | } 43 | 44 | int main() 45 | { 46 | int t; 47 | scanf("%d\n", &t); 48 | 49 | while (t--) 50 | { 51 | int num; 52 | scanf("%d", &num); 53 | 54 | dec2bin(num); 55 | } 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /Imakshat47_decimal2binaryUsingBitwise.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Binary Conversion 3 | 4 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. 5 | 6 | Examples: 7 | 8 | Input : 7 9 | Output : 111 10 | 11 | Input : 10 12 | Output : 1010 13 | 14 | Input: 33 15 | Output: 100001 16 | */ 17 | #include 18 | using namespace std; 19 | 20 | void dec2bin(int num) 21 | { 22 | for (int i = 31; i >= 0; --i) 23 | { 24 | int k = num >> i; 25 | if (k & 1) 26 | printf("1"); 27 | else 28 | { 29 | printf("0"); 30 | } 31 | } 32 | printf("\n"); 33 | } 34 | 35 | int main() 36 | { 37 | int t; 38 | scanf("%d\n", &t); 39 | 40 | while (t--) 41 | { 42 | int num; 43 | scanf("%d", &num); 44 | 45 | if (num == 0) 46 | { 47 | printf("0\n"); 48 | continue; 49 | } 50 | 51 | dec2bin(num); 52 | } 53 | 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Imakshat47_octal2binary.cpp: -------------------------------------------------------------------------------- 1 | // # Write a program to convert Octal to Binary 2 | /* 3 | Examples: 4 | 5 | Input : 25 6 | Output : 10101 7 | 8 | Input : 51 9 | Output : 101001 10 | 11 | Input: 5 12 | Output: 101 13 | */ 14 | 15 | #include 16 | using namespace std; 17 | 18 | int octal2bin(int octal) 19 | { 20 | int dec = 0, base = 1; 21 | 22 | while (octal != 0) 23 | { 24 | dec += (octal % 10) * base; 25 | base *= 8; 26 | octal /= 10; 27 | } 28 | 29 | int bin = 0; 30 | base = 1; 31 | 32 | while (dec != 0) 33 | { 34 | bin += ((dec % 2) * base); 35 | base *= 10; 36 | dec /= 2; 37 | } 38 | 39 | return bin; 40 | } 41 | 42 | int main() 43 | { 44 | int t; 45 | scanf("%d", &t); 46 | 47 | while (t--) 48 | { 49 | int num; 50 | scanf("%d", &num); 51 | printf("%d\n", octal2bin(num)); 52 | } 53 | 54 | return 0; 55 | } -------------------------------------------------------------------------------- /ImplementStrstr/CPP/ImplementFunctionStrstr.cpp: -------------------------------------------------------------------------------- 1 | /*Probem Statement: 2 | Input: 3 | s = HowdyDevelopers, x = Develop 4 | Output: 5 5 | Explanation: Develop is present as substring 6 | in HowdyDevelopers from index 5 (0 based 7 | indexing). 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | int strstr(string, string) 13 | int main() 14 | { 15 | int t;//t test cases 16 | cin>>t; 17 | while(t--) 18 | { 19 | string a; 20 | string b; 21 | cin>>a; 22 | cin>>b; 23 | cout< s; //stack to check balanced pairs 45 | for (int i = 0; i < A.size(); i++) 46 | { 47 | if (A[i] == '(') 48 | s.push(A[i]); //push in case of '(' 49 | if (A[i] == ')') 50 | { 51 | if (s.empty() || s.top() != '(') //if stack is empty or there are no corresponding opening parantheses,return 0 52 | return 0; 53 | else 54 | s.pop(); //pop the opening parentheses, to check for other pairs 55 | } 56 | } 57 | if (!s.empty())// if there remains a single opening parentheses without any closing parantheses, return false 58 | return 0; 59 | return 1; 60 | } 61 | -------------------------------------------------------------------------------- /InvertionCount/CPP/InvertionCount.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Inversion Count using Merge Sort 3 | * Time Complexity O(n log n) 4 | * 5 | * For each element of the array at Merge() we count the number of elements 6 | * greater than it on the left 7 | * and add it to inversionCount 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | int Merge(int arr[], int aux[], int low, int mid, int high) 14 | { 15 | int k = low, i = low, j = mid + 1; 16 | int inversionCount = 0; 17 | 18 | while (i <= mid && j <= high) 19 | { 20 | if (arr[i] <= arr[j]) { 21 | aux[k++] = arr[i++]; 22 | } 23 | else { 24 | aux[k++] = arr[j++]; 25 | inversionCount += (mid - i + 1); // NOTE 26 | } 27 | } 28 | 29 | while (i <= mid) 30 | aux[k++] = arr[i++]; 31 | 32 | for (int i = low; i <= high; i++) 33 | arr[i] = aux[i]; 34 | 35 | return inversionCount; 36 | } 37 | 38 | 39 | int mergeSort(int arr[], int aux[], int low, int high) 40 | { 41 | if (high == low) 42 | return 0; 43 | int mid = (low + ((high - low) >> 1)); 44 | int inversionCount = 0; 45 | 46 | inversionCount += mergeSort(arr, aux, low, mid); 47 | inversionCount += mergeSort(arr, aux, mid + 1, high); 48 | inversionCount += Merge(arr, aux, low, mid, high); 49 | 50 | return inversionCount; 51 | } 52 | 53 | int main() 54 | { 55 | int N; 56 | cout << "Enter the size of your array:\n"; 57 | cin >> N; 58 | 59 | int arr[N]; 60 | cout << "Enter your values into the array:\n"; 61 | for(int i=0; i> arr[i]; 63 | 64 | int aux[N]; 65 | for (int i = 0; i < N; i++) 66 | aux[i] = arr[i]; 67 | 68 | cout << "Inversion count is " << mergeSort(arr, aux, 0, N - 1); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /Job Sequencing/sequencing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class node{ 5 | public: 6 | int d,p,t; 7 | bool operator < (node n) 8 | { 9 | if(p lst; 20 | node pt; 21 | cout<<"Enter no of entries 22 | "; 23 | cin>>n; 24 | for(i=0;i>p>>d>>t; 29 | pt.d=d; 30 | pt.p=p; 31 | pt.t=t; 32 | lst.push_back(pt); 33 | } 34 | int maxd=0; 35 | lst.sort(); 36 | lst.reverse(); 37 | cout<<" 38 | sorted list 39 | "; 40 | list :: iterator itr=lst.begin(); 41 | while(itr!=lst.end()){ 42 | pt=*itr; 43 | if(maxd=pt.t) 56 | min=pt.t; 57 | else 58 | min=pt.d; 59 | 60 | if(maxd>=min) 61 | profit+=min*pt.p; 62 | else 63 | profit+=maxd*pt.p; 64 | itr++;maxd=maxd-min; 65 | 66 | } 67 | cout<<"profit is : "< 2 | using namespace std; 3 | 4 | const int mod = 1e9 + 7; 5 | ll pw(ll a, ll b) { 6 | ll ret = 1; 7 | while (b) { 8 | if (b % 2) 9 | ret = (ret * a) % mod; 10 | a = (a * a) % mod; 11 | b >>= 1; 12 | } 13 | return ret % mod; 14 | } 15 | 16 | int f[100500]; 17 | int n; 18 | char str[100500]; 19 | void buildF() { 20 | int j = 0; 21 | for (int i = 1; i < n; i++) { 22 | if (str[i] == str[j]) 23 | f[i] = ++j; 24 | else { 25 | while (j && str[j] != str[i]) 26 | j = f[j - 1]; 27 | 28 | if (str[i] == str[j]) 29 | f[i] = ++j; 30 | else 31 | f[i] = 0; 32 | } 33 | } 34 | 35 | } 36 | int main() { 37 | scanf("%s",str); 38 | n=strlen(str); 39 | buildF(); 40 | 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Kadane'sAlgorithm/CPP/Kadane'sAlgo.C++: -------------------------------------------------------------------------------- 1 | 2 | //KADANE'S algorithm is able to find the MaximumSum of a Contiguous Subarray in array with the runtime of O(n)... 3 | 4 | #include 5 | using namespace std; 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | int a[1000], cs=0, ms=0; 10 | for(int i=0, i < n, i++){ 11 | cin>>a[i]; 12 | } 13 | //Kadane's algorithm for Subarray Sum 14 | for(int i=0; i 8 | using namespace std; 9 | 10 | int factorial(int n) 11 | { 12 | int fact = 1; 13 | while (n != 0) { 14 | fact = fact * n; 15 | n--; 16 | } 17 | return fact; 18 | } 19 | bool isKrishnamurthy(int n) 20 | { 21 | int sum = 0; 22 | 23 | int temp = n; 24 | while (temp != 0) { 25 | sum += factorial(temp % 10); 26 | 27 | temp = temp / 10; 28 | } 29 | return (sum == n); 30 | } 31 | int main() 32 | { 33 | int n; 34 | cout<<"Enter the Number :"; 35 | cin>>n; 36 | if (isKrishnamurthy(n)) 37 | cout << "YES it is a Krishnamurthy Number "< 2 | using namespace std; 3 | 4 | int* lis(int* arr, int n){ 5 | 6 | int* result1 = new int[n]; 7 | result1[0] = 1; 8 | 9 | for(int i=1 ; i= 0 ; j--){ 13 | 14 | if(arr[j] >= arr[i]) 15 | continue; 16 | int temp = result1[j] + 1; 17 | if(temp > result1[i]) 18 | result1[i] = temp; 19 | } 20 | } 21 | return result1; 22 | } 23 | 24 | int* lis_b(int* arr, int n){ 25 | 26 | int* result2 = new int[n]; 27 | result2[n-1] = 1; 28 | 29 | for(int i=n-2 ; i >= 0 ; i--){ 30 | 31 | result2[i] = 1; 32 | for(int j=i+1 ; j= arr[i]) 35 | continue; 36 | int temp = result2[j] + 1; 37 | if(temp > result2[i]) 38 | result2[i] = temp; 39 | } 40 | } 41 | return result2; 42 | } 43 | 44 | int longestBitonicSubarray(int * arr, int n){ 45 | 46 | int* lis_ = lis(arr, n); 47 | int* dis_ = lis_b(arr, n); 48 | 49 | int lengthLBS = 0; 50 | for(int i=0 ; i lengthLBS) 54 | lengthLBS = temp; 55 | 56 | } 57 | return lengthLBS; 58 | } 59 | int main(){ 60 | int n; 61 | cin >> n; 62 | 63 | int * arr = new int[n]; 64 | for(int i = 0; i> arr[i]; 66 | } 67 | 68 | int lengthLBS = longestBitonicSubarray(arr ,n); 69 | cresult2 << lengthLBS << endl; 70 | 71 | delete [] arr; 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /Mad libs game.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[ ]: 5 | 6 | 7 | """ Mad Libs Generator 8 | ---------------------------------------- 9 | """ 10 | #Loop back to this point once code finishes 11 | loop = 1 12 | while (loop < 10): 13 | #All the questions that the program asks the user 14 | noun1 = input("Choose 1st noun: ") 15 | noun2 = input("Choose 2nd noun: ") 16 | noun3 = input("Choose 3rd noun: ") 17 | place = input("Name a place: ") 18 | adjective = input("Choose an adjective (Describing word): ") 19 | #Displays the story based on the users input 20 | print ("------------------------------------------") 21 | print ("Hello ",noun1,",") 22 | print ("Myself ", noun2,",") 23 | print ("Welcome to ",place) 24 | print ("Today's weather is ",adjective,".") 25 | print () 26 | print ("I think you want to meet",noun3,",") 27 | print ("Well here he is.") 28 | print ("------------------------------------------") 29 | #Loop back to "loop = 1" 30 | loop = loop + 1 31 | 32 | -------------------------------------------------------------------------------- /PatternProblems/HollowDiamondInscribedInRectanglePattern/C++/HollowDiamondInscribedInRectanglePattern.C++: -------------------------------------------------------------------------------- 1 | //Hollow Diamond Inscribed in a Rectangle Pattern 2 | 3 | 4 | /* Input: 5 5 | 6 | Output: 7 | 8 | * * * * * * * * * * 9 | * * * * * * * * 10 | * * * * * * 11 | * * * * 12 | * * 13 | * * 14 | * * * * 15 | * * * * * * 16 | * * * * * * * * 17 | * * * * * * * * * * 18 | 19 | 20 | Solution for diamond inscribed inside rectangle In C++ :- */ 21 | 22 | #include 23 | using namespace std; 24 | int main() 25 | { 26 | int i, j, n; 27 | cin >> n; 28 | // upper half of the pattern 29 | for(i = 0; i < n; i++) 30 | { 31 | for(j = 0; j < (2 * n); j++) 32 | { 33 | if(i + j <= n - 1) // upper left triangle 34 | cout << "*"; 35 | else 36 | cout << " "; 37 | if((i + n) <= j) // upper right triangle 38 | cout << "*"; 39 | else 40 | cout << " "; 41 | } 42 | cout << "\n"; 43 | } 44 | // bottom half of the pattern 45 | for(i = 0; i < n; i++) 46 | { 47 | for(j = 0; j < (2 * n); j++) 48 | { 49 | if(i >= j) // bottom left triangle 50 | cout << "*"; 51 | else 52 | cout << " "; 53 | if(i >= (2 * n - 1) - j) // bottom right triangle 54 | cout << "*"; 55 | else 56 | cout << " "; 57 | } 58 | cout << "\n"; 59 | } 60 | return 0; 61 | } -------------------------------------------------------------------------------- /PatternProblems/HollowDiamondInscribedInRectanglePattern/C/HollowDiamondInscribedInRectanglePattern.C: -------------------------------------------------------------------------------- 1 | //Hollow Diamond Inscribed in a Rectangle Pattern 2 | 3 | 4 | /* Input: 5 5 | 6 | Output: 7 | 8 | * * * * * * * * * * 9 | * * * * * * * * 10 | * * * * * * 11 | * * * * 12 | * * 13 | * * 14 | * * * * 15 | * * * * * * 16 | * * * * * * * * 17 | * * * * * * * * * * 18 | 19 | Solution for diamond inscribed inside rectangle In C :- */ 20 | 21 | #include 22 | int main() 23 | { 24 | int i, j, n; 25 | scanf("%d", &n); 26 | // upper half of the pattern 27 | for(i = 0; i < n; i++) 28 | { 29 | for(j = 0; j < (2 * n); j++) 30 | { 31 | if(i + j <= n - 1) // upper left triangle 32 | printf("*"); 33 | else 34 | printf(" "); 35 | if((i + n) <= j) // upper right triangle 36 | printf("*"); 37 | else 38 | printf(" "); 39 | } 40 | printf("\n"); 41 | } 42 | // bottom half of the pattern 43 | for(i = 0; i < n; i++) 44 | { 45 | for(j = 0; j < (2 * n); j++) 46 | { 47 | if(i >= j) //bottom left triangle 48 | printf("*"); 49 | else 50 | printf(" "); 51 | if(i >= (2 * n - 1) - j) // bottom right triangle 52 | printf("*"); 53 | else 54 | printf(" "); 55 | } 56 | printf("\n"); 57 | } 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /PatternProblems/PyramidPatternProblem/C++/PyramidPatternProblem1.cpp: -------------------------------------------------------------------------------- 1 | //Solid rectangular star pattern: 2 | //Number of rows: 3 3 | //Number of columns: 5 4 | 5 | //* * * * * 6 | //* * * * * 7 | //* * * * * 8 | //Program to print solid rectangular star pattern 9 | #include 10 | 11 | using namespace std; 12 | 13 | /* Function to print solid rectangle*/ 14 | 15 | void solid_rectangle(int n, int m) 16 | 17 | { 18 | 19 | int i, j; 20 | 21 | for (i = 1; i <= n; i++) 22 | 23 | { 24 | 25 | for (j = 1; j <= m; j++) 26 | 27 | { 28 | 29 | cout << “*”; 30 | 31 | } 32 | 33 | cout << endl; 34 | 35 | } 36 | 37 | } 38 | 39 | int main() 40 | 41 | { 42 | 43 | int rows, columns; 44 | 45 | cout << “nEnter the number of rows : “; 46 | 47 | cin >> rows; 48 | 49 | cout << “nEnter the number of columns : “; 50 | 51 | cin >> columns; 52 | 53 | cout << endl; 54 | 55 | solid_rectangle(rows, columns); 56 | 57 | return 0; 58 | 59 | } -------------------------------------------------------------------------------- /PatternProblems/PyramidPatternProblem/C/pyramidpattern1.c: -------------------------------------------------------------------------------- 1 | /* C program to print solid rectangle star pattern */ 2 | //Solid rectangular star pattern: 3 | //Number of rows: 3 4 | //Number of columns: 5 5 | 6 | //* * * * * 7 | //* * * * * 8 | //* * * * * 9 | //Program to print solid rectangular star pattern 10 | #include 11 | void solid_rectangle(int n, int m) 12 | 13 | { 14 | 15 | int i, j; 16 | 17 | for (i = 1; i <= n; i++) 18 | 19 | { 20 | 21 | for (j = 1; j <= m; j++) 22 | 23 | { 24 | 25 | printf(“*”); 26 | 27 | } 28 | 29 | printf(“n”); 30 | 31 | } 32 | 33 | } 34 | 35 | int main() 36 | 37 | { 38 | 39 | int rows, columns; 40 | 41 | printf(“nEnter the number of rows : “); 42 | 43 | scanf(“%d”, &rows); 44 | 45 | printf(“nEnter the number of columns : “); 46 | 47 | scanf(“%d”, &columns); 48 | 49 | printf(“n”); 50 | 51 | solid_rectangle(rows, columns); 52 | 53 | return 0; 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /PatternProblems/PyramidPatternProblem/JAVA/PyramidPattern1.java: -------------------------------------------------------------------------------- 1 | //Solid rectangular star pattern: 2 | //Number of rows: 3 3 | //Number of columns: 5 4 | 5 | //* * * * * 6 | //* * * * * 7 | //* * * * * 8 | //Program to print solid rectangular star pattern 9 | import java.util.*; 10 | 11 | public class Main 12 | 13 | { 14 | 15 | static void solid_rectangle(int n, int m) 16 | 17 | { 18 | 19 | int i, j; 20 | 21 | for (i = 1; i <= n; i++) 22 | 23 | { 24 | 25 | for (j = 1; j <= m; j++) 26 | 27 | { 28 | 29 | System.out.print(“*”); 30 | 31 | } 32 | 33 | System.out.print(“n”); 34 | 35 | } 36 | 37 | 38 | 39 | } 40 | 41 | public static void main (String args[]) 42 | 43 | { 44 | 45 | int rows, columns; 46 | 47 | Scanner sc = new Scanner(System.in); 48 | 49 | System.out.print(“nEnter the number of rows : “); 50 | 51 | rows = sc.nextInt(); 52 | 53 | System.out.print(“nEnter the number of columns : “); 54 | 55 | columns = sc.nextInt(); 56 | 57 | System.out.print(“n”); 58 | 59 | solid_rectangle(rows, columns); 60 | 61 | } 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /PatternProblems/PyramidPatternProblem/PYTHON/pyramidpattern1.py: -------------------------------------------------------------------------------- 1 | # Python program to print solid rectangle star pattern 2 | 3 | 4 | #Number of rows: 3 5 | #Number of columns: 5 6 | 7 | #* * * * * 8 | #* * * * * 9 | #* * * * * 10 | #Program to print solid rectangular star pattern 11 | # Function to print solid rectangle 12 | 13 | def solid_rectangle(n, m): 14 | 15 | for i in range(1, n+1): 16 | 17 | for j in range(1, m+1): 18 | 19 | print(“*”, end = “”) 20 | 21 | print() 22 | 23 | rows = int(input(“Enter the number of rows : “)) 24 | 25 | columns = int(input(“Enter the number of columns : “)) 26 | 27 | solid_rectangle(rows, columns) -------------------------------------------------------------------------------- /Recursion/Flood_fill_algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int a[1000][1000]; 5 | int m,n; 6 | 7 | void fill(int x,int y,int k, int prev){ 8 | if(x>=n || x<0 || y>=m || y<0) 9 | return; 10 | if(a[x][y] != prev) 11 | return; 12 | if(a[x][y] == k){ 13 | return; 14 | } 15 | 16 | a[x][y] = k; 17 | 18 | fill(x+1, y, k, prev); 19 | fill(x-1, y, k, prev); 20 | fill(x, y+1, k, prev); 21 | fill(x, y-1, k, prev); 22 | return; 23 | } 24 | 25 | int main() { 26 | ios_base::sync_with_stdio(0); 27 | int t, i, j, k, p, q, r, x, y, u, v; 28 | cin>>t; 29 | while(t--){ 30 | cin>>n>>m; 31 | for(i=0;i>a[i][j]; 34 | } 35 | } 36 | cin>>x>>y>>k; 37 | fill(x, y, k, a[x][y]); 38 | for(i=0;i 5 | 6 | #define ll long long 7 | #define ld long double 8 | #define ar array 9 | 10 | #define pb push_back 11 | #define vt vector 12 | #define REP(i,a,b) for(int i = a; i <= b; i++) 13 | 14 | 15 | using namespace std; 16 | 17 | vector rotate(vector vals, int num, int d){//vals = array of integers, num- number of places shift, d=length of array 18 | vector ans; 19 | for(int i = d-num; i < d; i++){ 20 | ans.pb(vals[i]); 21 | } 22 | for(int i = 0; i< d-num; i++){ 23 | ans.pb(vals[i]); 24 | } 25 | return ans; 26 | } 27 | 28 | 29 | int main(){ 30 | ios_base::sync_with_stdio(0); 31 | cin.tie(0); 32 | int rot; 33 | vector test = {1,2,3,4,5,6}; 34 | cout << "how many rotations do you want: "<> rot; 36 | vector print = rotate(test,rot,6); 37 | for(int i =0; i< 6; i++){ 38 | cout << print[i] << " "; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /RotateTheArray/C/RotateArrayByN.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int m,i,n; 6 | 7 | printf("Enter number of elements in the array \n"); 8 | scanf("%d", &m); 9 | //Initialize array 10 | int arr[m]; 11 | 12 | for (i = 0; i < m; i++) 13 | { 14 | printf("Enter integer no. %d :", (i+1)); 15 | scanf("%d", &arr[i]); 16 | } 17 | //Calculate length of array arr 18 | int length = sizeof(arr)/sizeof(arr[0]); 19 | 20 | 21 | //n determine the number of times an array should be rotated 22 | printf("Enter number of times to be left rotated\n"); 23 | scanf("%d",&n); 24 | 25 | printf("\n**********************\n"); 26 | 27 | //Displays original array 28 | printf("Original array: \n"); 29 | for (i = 0; i < length; i++) { 30 | printf("%d ", arr[i]); 31 | } 32 | 33 | //Rotate the given array by n times toward left 34 | for(i = 0; i < n; i++){ 35 | int j, first; 36 | //Stores the first element of the array 37 | first = arr[0]; 38 | 39 | for(j = 0; j < length-1; j++){ 40 | //Shift element of array by one 41 | arr[j] = arr[j+1]; 42 | } 43 | //First element of array will be added to the end 44 | arr[j] = first; 45 | } 46 | printf("\n**********************\n"); 47 | 48 | 49 | //result after rotation 50 | printf("Array after left rotation: \n"); 51 | for(i = 0; i < length; i++){ 52 | printf("%d ", arr[i]); 53 | } 54 | printf("\n**********************\n"); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /RotateTheArray/Java/RotateTheArray.java: -------------------------------------------------------------------------------- 1 | public class RotateTheArray { 2 | 3 | private char[] array; 4 | private int rotateBy; 5 | 6 | public RotateTheArray() { 7 | setArray(); 8 | rotateBy = 0; 9 | 10 | } 11 | 12 | public static void main(String[] args) { 13 | 14 | RotateTheArray r = new RotateTheArray(); 15 | r.printTheArray(); 16 | r.rotateBy = 4; 17 | r.rotateArray(); 18 | r.printTheArray(); 19 | r.rotateBy = 6; 20 | r.rotateArray(); 21 | r.printTheArray(); 22 | } 23 | 24 | private void rotateArray() { 25 | 26 | int k; 27 | char val; 28 | 29 | for(int i=0; i 2 | using namespace std; 3 | int main(){ 4 | //defining the array 5 | int arr1[] = { 1, 45, 54, 71, 76, 12 }; 6 | int arr2[] = { 1, 7, 5, 4, 6, 12 }; 7 | int n1 = sizeof(arr1) / sizeof(arr1[0]); 8 | int n2 = sizeof(arr2) / sizeof(arr2[0]); 9 | sort(arr1, arr1 + n1); 10 | sort(arr2, arr2 + n2); 11 | cout << "First Array: "; 12 | for (int i = 0; i < n1; i++) 13 | cout << arr1[i] << " "; 14 | cout << endl; 15 | cout << "Second Array: "; 16 | for (int i = 0; i < n2; i++) 17 | cout << arr2[i] << " "; 18 | cout << endl; 19 | vector v(n1 + n2); 20 | vector::iterator it, st; 21 | //finding the common elements 22 | it = set_intersection(arr1, arr1 + n1, arr2, arr2 + n2, v.begin()); 23 | cout << "\nCommon elements:\n"; 24 | for (st = v.begin(); st != it; ++st) 25 | cout << *st << ", "; 26 | cout << '\n'; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /RotateTheArray/different_array_rotations/left_rotation_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | int r; 7 | cin>>n>>r; 8 | int arr[n]; 9 | for(int i=0; i>arr[i]; 12 | } 13 | int k=arr[0]; 14 | for(int i=0; i 2 | using namespace std; 3 | int main() 4 | { 5 | int T; //test cases 6 | cin>>T; 7 | for(int x=0; x>n; 11 | int arr[n][n]; 12 | for(i=0;i>arr[i][j]; 17 | } 18 | } 19 | for(i=0; i=0; j--) 31 | { 32 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n, d; 11 | cin>>n; 12 | int arr[n]; 13 | for(int i=0; i>arr[i]; 16 | } 17 | cin>>d; 18 | for(int j=d; j 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n, m; 10 | cin>>m>>n; 11 | int arr[m][n]; 12 | for(int i=0; i>arr[i][j]; 17 | } 18 | } 19 | int k=0, l=0, i; 20 | while(k=l; i--) 35 | { 36 | cout<=k; i--) 43 | { 44 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int t, f=0; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int f=0; 11 | long long int n; 12 | cin>>n; 13 | long long int a[n]; 14 | long long int b[n]; 15 | for(int i=0; i>a[i]; 18 | } 19 | for(int i=0; i>b[i]; 22 | } 23 | sort(a, a+n); 24 | sort(b, b+n); 25 | // for(int i=0; i Frequency 11 | . 12 | . 13 | Maximum File added 14 | 15 | - Constraints: 16 | 12 25 | 3->1 26 | 1->2 27 | Maximum files added by any contributor= 2 28 | -------------------------------------------------------------------------------- /STL-unordered_map/freq_count.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include // header required to use unordered_map container. 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; cin>>n; 9 | int A[n], max_freq=0; 10 | // declaration for unordered map of type,i.e both key-value should be integer. 11 | unordered_map umap; 12 | for(int i=0;i>A[i]; 15 | umap[A[i]]++; // incrementing count of unique keys in map. 16 | } 17 | 18 | // iterating in map 19 | for(auto it : umap) // auto keyword is used to define an iterator. 20 | { 21 | // it.first accesses key and it.second gives corresponding value. 22 | cout<"<max_freq) 24 | max_freq=it.second; 25 | } 26 | cout<<"Maximum files added by any contributor= "<data < data ){ 16 | parent = temp2; 17 | temp2 = temp2->next; 18 | if(temp2 == NULL) 19 | break; 20 | } 21 | 22 | if(temp2 == head){ 23 | temp->next = temp2; 24 | head = temp; 25 | } 26 | else{ 27 | temp->next = temp2; 28 | parent->next= temp; 29 | } 30 | return head; 31 | } -------------------------------------------------------------------------------- /STL/CPP/minimum_cost_of_ropes.cpp: -------------------------------------------------------------------------------- 1 | // Question // 2 | /** 3 | Given n ropes of different lengths, we need to connect these ropes into one rope. 4 | We can connect only 2 ropes at a time. The cost required to connect 2 ropes is equal 5 | to sum of their lengths. The length of this connected rope is also equal to the sum 6 | of their lengths. This process is repeated until n ropes are connected into a single 7 | rope. Find the min possible cost required to connect all ropes. 8 | 9 | Input : ropes = [8, 4, 6, 12] 10 | Output: 58 11 | Explanation: The optimal way to connect ropes is as follows 12 | 1. Connect the ropes of length 4 and 6 (cost is 10). Ropes after connecting: [8, 10, 12] 13 | 2. Connect the ropes of length 8 and 10 (cost is 18). Ropes after connecting: [18, 12] 14 | 3. Connect the ropes of length 18 and 12 (cost is 30). 15 | Total cost to connect the ropes is 10 + 18 + 30 = 58 16 | 17 | **/ 18 | // use of C++ STL priority queue // 19 | // Solution // 20 | #include 21 | #define ll long long int 22 | using namespace std; 23 | 24 | int main() { 25 | //code 26 | int t,n; 27 | cin>>t; 28 | while(t--) 29 | { 30 | cin>>n; 31 | ll a[n]; 32 | priority_queue p; // STL priority queue 33 | for(int i=0;i>a[i]; 36 | p.push(-a[i]); // inserting negative value to act as min priority queue 37 | } 38 | ll cost=0; 39 | while(p.size()>1) 40 | { 41 | ll a=p.top(); 42 | p.pop(); 43 | a=-a; 44 | ll b=p.top(); 45 | b=-b; 46 | p.pop(); 47 | cost+=a+b; 48 | p.push(-(a+b)); 49 | } 50 | cout< p; 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /STL/CPP/partition in C++ STL: -------------------------------------------------------------------------------- 1 | // C++ code to demonstrate the working of 2 | // partition() and is_partitioned() 3 | #include 4 | #include // for partition algorithm 5 | #include // for vector 6 | using namespace std; 7 | int main() 8 | { 9 | // Initializing vector 10 | vector vect = { 2, 1, 5, 6, 8, 7 }; 11 | 12 | // Checking if vector is partitioned 13 | // using is_partitioned() 14 | is_partitioned(vect.begin(), vect.end(), [](int x) 15 | { 16 | return x%2==0; 17 | 18 | })? 19 | 20 | cout << "Vector is partitioned": 21 | cout << "Vector is not partitioned"; 22 | cout << endl; 23 | 24 | // partitioning vector using partition() 25 | partition(vect.begin(), vect.end(), [](int x) 26 | { 27 | return x%2==0; 28 | 29 | }); 30 | 31 | // Checking if vector is partitioned 32 | // using is_partitioned() 33 | is_partitioned(vect.begin(), vect.end(), [](int x) 34 | { 35 | return x%2==0; 36 | 37 | })? 38 | 39 | cout << "Now, vector is partitioned after partition operation": 40 | cout << "Vector is still not partitioned after partition operation"; 41 | cout << endl; 42 | 43 | // Displaying partitioned Vector 44 | cout << "The partitioned vector is : "; 45 | for (int &x : vect) cout << x << " "; 46 | 47 | return 0; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /STL/CPP/reverse-ll.cpp: -------------------------------------------------------------------------------- 1 | // struct Node 2 | // { 3 | // int data; 4 | // struct Node *next; 5 | // } 6 | 7 | struct Node* reverseList(struct Node *head) 8 | { 9 | 10 | Node* prev = NULL; 11 | Node* curr = head; 12 | Node* next = head->next; 13 | 14 | if(curr == NULL || next == NULL) 15 | return head; 16 | 17 | while(curr != NULL){ 18 | next = curr->next; 19 | curr->next = prev; 20 | prev = curr; 21 | curr = next; 22 | } 23 | return prev; 24 | } -------------------------------------------------------------------------------- /STL/CPP/subarray_sum.cpp: -------------------------------------------------------------------------------- 1 | // Given an unsorted array A of size N of non-negative integers 2 | // find a continuous sub-array which adds to a given number S. 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() { 9 | //code 10 | int t; 11 | cin>>t; 12 | while(t--){ 13 | int n,s; 14 | cin>>n>>s; 15 | int arr[n]; 16 | 17 | for(int i = 0; i < n; i++) cin>>arr[i]; 18 | 19 | deque > dq; 20 | int curr_sum = 0,f = 0; 21 | 22 | for(int i = 0; i < n; i++){ 23 | 24 | dq.push_back({arr[i],i}); 25 | curr_sum += arr[i]; 26 | 27 | while(curr_sum > s && !dq.empty()){ 28 | curr_sum -= dq.front().first; 29 | dq.pop_front(); 30 | } 31 | 32 | 33 | 34 | if(curr_sum == s){ 35 | cout<= 2; k--){ 11 | 12 | for(i = 0, j = n-1; i < j;){ 13 | 14 | if(arr[i] + arr[j] == arr[k]){ 15 | ans++; 16 | i++; 17 | j--; 18 | } 19 | else if(arr[i] + arr[j] < arr[k]){ 20 | i++; 21 | } 22 | else{ 23 | j--; 24 | } 25 | } 26 | } 27 | return ans; 28 | } -------------------------------------------------------------------------------- /STL/CPP/valid_parentheses.cpp: -------------------------------------------------------------------------------- 1 | // Balanced Brackets or Valid Parentheses using C++ STL stack 2 | // Links to Question 3 | // HackerRank: https://www.hackerrank.com/challenges/balanced-brackets/problem 4 | // LeetCode: https://leetcode.com/problems/valid-parentheses/ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | string isBalanced(string s) { 13 | stack st; 14 | for (char c : s) { 15 | if (c == '(' || c == '[' || c == '{') { 16 | st.push(c); 17 | } 18 | else if (st.empty()) { 19 | return "NO"; 20 | } 21 | else if (c == ')') { 22 | if (st.top() == '(') { 23 | st.pop(); 24 | } 25 | else { 26 | return "NO"; 27 | } 28 | } 29 | else if (c == '}') { 30 | if (st.top() == '{') { 31 | st.pop(); 32 | } 33 | else { 34 | return "NO"; 35 | } 36 | } 37 | else if (c == ']') { 38 | if (st.top() == '[') { 39 | st.pop(); 40 | } 41 | else { 42 | return "NO"; 43 | } 44 | } 45 | } 46 | return st.empty() ? "YES" : "NO"; 47 | } 48 | 49 | int main() { 50 | cout << isBalanced("()") << endl; 51 | cout << isBalanced("()[]{}") << endl; 52 | cout << isBalanced("(]") << endl; 53 | cout << isBalanced("([)]") << endl; 54 | cout << isBalanced("{[]}") << endl; 55 | cin.get(); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /SortingAlgorithms/C++/BucketSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void temp_sort(vector&arr,int n,int val) 4 | { 5 | vector>buckets(11); 6 | int place=pow(10,val); 7 | for(int i=0;ic; 14 | for(int i=0;i<=10;i++) 15 | { 16 | for(int k=0;k&arr,int n) 24 | { 25 | int max_ele=arr[0]; 26 | for(int i=0;i>n; 39 | vectorarr(n); 40 | for(int i=0;i>arr[i]; 42 | } 43 | bucket_sort(arr,n); 44 | for(int i=0;i 2 | using namespace std; 3 | 4 | int k=0; 5 | 6 | void sort_func(int A[],int B[],int n) 7 | { 8 | int count[k+1],t; 9 | for(int i=0;i<=k;i++) 10 | { 11 | count[i] = 0; 12 | } 13 | for(int i=0;i>n; 34 | int A[n],B[n]; 35 | cout<<"Enter the array elements: "; 36 | for(int i=0;i>A[i]; 39 | if(A[i]>k) 40 | { 41 | k = A[i]; 42 | } 43 | } 44 | 45 | sort_func(A,B,n); 46 | 47 | for(int i=1;i<=n;i++) 48 | { 49 | cout< 2 | using namespace std; 3 | 4 | void insertionSort(int arr[], int n) 5 | { 6 | int i, key, j; 7 | for (i = 1; i < n; i++) 8 | { 9 | key = arr[i]; 10 | j = i - 1; 11 | 12 | while (j >= 0 && arr[j] > key) 13 | { 14 | arr[j + 1] = arr[j]; 15 | j--; 16 | } 17 | arr[j + 1] = key; 18 | } 19 | } 20 | int main() 21 | { 22 | int arr[] = { 2, 1, 3, 4, 5 }; 23 | int n = sizeof(arr) / sizeof(arr[0]); 24 | 25 | insertionSort(arr, n); 26 | 27 | for (int i = 0; i < n; i++) 28 | cout << arr[i] << " "; 29 | cout << "\n"; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /SortingAlgorithms/C++/SelectionSort.CPP: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void selectionSort(int arr[], int n) 5 | { 6 | int i, j, min_idx; 7 | 8 | for (i = 0; i < n-1; i++) 9 | { 10 | min_idx = i; 11 | for (j = i+1; j < n; j++) 12 | if (arr[min_idx] > arr[j]) 13 | min_idx = j; 14 | 15 | int temp = arr[min_idx]; 16 | arr[min_idx] = arr[i]; 17 | arr[i] = temp; 18 | } 19 | } 20 | 21 | int main() 22 | { 23 | int arr[] = {2, 1, 3, 5, 4}; 24 | int n = sizeof(arr)/sizeof(arr[0]); 25 | selectionSort(arr, n); 26 | for (int i=0; i < n; i++) 27 | cout << arr[i] << " "; 28 | cout << "\n"; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /SortingAlgorithms/C++/zahinekbal_bubbleSort_STL(Comparater-Function).C++: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | bool compare(int a, int b){ 7 | 8 | /*optional but here i am giving it to show how comparing is working with the inputs 9 | (printing the comparing values check it output)*/ 10 | 11 | cout<<"Comparing"<b; 13 | } 14 | 15 | //Bubble Sort 16 | 17 | /* bool(&cmp)(int a, int b) this is how you pass the function as a parameter or 18 | you accept a function as a parameter inside any function */ 19 | 20 | void bubble_sort(int a[], int n, bool(&cmp)(int a, int b)){ 21 | for(int itr=1; itr<=n-1; itr++){ 22 | for(int j=0; j<=(n-itr-1); itr++) 23 | { 24 | if( cmp(a[j], a[j+1]) ) { 25 | swap( a[j], a[j+1] ); 26 | } 27 | } 28 | } 29 | } 30 | 31 | int main(){ 32 | int n, key; 33 | cin>>n; 34 | int a[1000]; 35 | for(int i=0; i>a[i]; 37 | } 38 | bubble_sort(a, n, compare); 39 | for(int i=0; i 2 | 3 | void swap(int *a, int *b) { 4 | int *temp = a; 5 | a = b; 6 | b = temp; 7 | } 8 | 9 | void heapify(int arr[], int n, int i) { 10 | int largest = i; 11 | int left = 2 * i + 1; 12 | int right = 2 * i + 2; 13 | if (left < n && arr[left] > arr[largest]) { 14 | largest = left; 15 | } 16 | if (right < n && arr[right] > arr[largest]) { 17 | largest = left 18 | } 19 | if (i != largest) { 20 | swap(&arr[i], &arr[largest]); 21 | heapify(arr, n, largest); 22 | } 23 | } 24 | 25 | void heap_sort(int arr[], int n) { 26 | int i; 27 | for (i = (n / 2) - 1; i > 0; i--) { 28 | heapify(A, n, i); 29 | for (i = n - 1; i > 0; i--) { 30 | swap(&arr[0], &arr[i]); 31 | heapify(arr, i, 0); 32 | } 33 | } 34 | } 35 | 36 | int main() { 37 | n = 5; 38 | arr[5] = {2, 45, 87, 34, 56}; 39 | heap_sort(arr, n); 40 | for (int i = 0; i < n; i++) 41 | printf("%d\t"); 42 | } -------------------------------------------------------------------------------- /SortingAlgorithms/Kotlin/BubbleSort.kt: -------------------------------------------------------------------------------- 1 | class BubbleSort { 2 | companion object { 3 | @JvmStatic 4 | fun main(args: Array) { 5 | val array = arrayOf(64, 34, 25, 12, 22, 11, 90) 6 | println("Before Sorted") 7 | printArray(array) 8 | 9 | bubbleSort(array) 10 | println("Sorted Array") 11 | printArray(array) 12 | } 13 | 14 | private fun printArray(arr: Array) { 15 | for (element in arr) { 16 | print("$element ") 17 | } 18 | println() 19 | } 20 | 21 | private fun bubbleSort(arr: Array) { 22 | for (i in 0 until arr.size - 1) { 23 | for (j in 0 until arr.size-i-1) { 24 | if (arr[j] > arr[j+1]) { 25 | val temp = arr[j] 26 | arr[j] = arr[j+1] 27 | arr[j+1] = temp 28 | } 29 | } 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /SortingAlgorithms/java/BubbleSort.java: -------------------------------------------------------------------------------- 1 | public class BubbleSortExample { 2 | static void bubbleSort(int[] arr) { 3 | int n = arr.length; 4 | int temp = 0; 5 | for(int i=0; i < n; i++){ 6 | for(int j=1; j < (n-i); j++){ 7 | if(arr[j-1] > arr[j]){ 8 | //swap elements 9 | temp = arr[j-1]; 10 | arr[j-1] = arr[j]; 11 | arr[j] = temp; 12 | } 13 | 14 | } 15 | } 16 | 17 | } 18 | public static void main(String[] args) { 19 | int arr[] ={3,60,35,2,45,320,5}; 20 | 21 | System.out.println("Array Before Bubble Sort"); 22 | for(int i=0; i < arr.length; i++){ 23 | System.out.print(arr[i] + " "); 24 | } 25 | System.out.println(); 26 | 27 | bubbleSort(arr);//sorting array elements using bubble sort 28 | 29 | System.out.println("Array After Bubble Sort"); 30 | for(int i=0; i < arr.length; i++){ 31 | System.out.print(arr[i] + " "); 32 | } 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /SortingAlgorithms/java/InsertionSort.java: -------------------------------------------------------------------------------- 1 | class InsertionSort { 2 | void sort(int arr[]) 3 | { 4 | for (int i = 1; i < arr.length; ++i) { 5 | int key = arr[i]; 6 | int j = i - 1; 7 | 8 | while (j >= 0 && arr[j] > key) { 9 | arr[j + 1] = arr[j]; 10 | j--; 11 | } 12 | arr[j + 1] = key; 13 | } 14 | } 15 | 16 | public static void main(String args[]) 17 | { 18 | int arr[] = { 2, 1, 3, 4, 5 }; 19 | 20 | new InsertionSort().sort(arr); 21 | 22 | for (int i = 0; i < arr.length; ++i) 23 | System.out.print(arr[i] + " "); 24 | 25 | System.out.println(); 26 | } 27 | } -------------------------------------------------------------------------------- /SortingAlgorithms/java/SelectionSort.java: -------------------------------------------------------------------------------- 1 | class SelectionSort 2 | { 3 | void func_SelectionSort(int arr[]) 4 | { 5 | int n = arr.length; 6 | for (int i = 0; i < n-1; i++) 7 | { 8 | int min_idx = i; 9 | for (int j = i+1; j < n; j++) 10 | if (arr[min_idx] > arr[j]) 11 | min_idx = j; 12 | 13 | int temp = arr[min_idx]; 14 | arr[min_idx] = arr[i]; 15 | arr[i] = temp; 16 | } 17 | } 18 | 19 | public static void main(String args[]) 20 | { 21 | int arr[] = {2,1,3,5,4}; 22 | new SelectionSort().func_SelectionSort(arr); 23 | for (int i=0; i 0: 7 | times+=1 8 | for i in range(gap,len(array)): 9 | temp = array[i] 10 | j = i 11 | while j >= gap and array[j-gap] >temp: 12 | array[j] = array[j-gap] 13 | j -= gap 14 | comparison+=1 15 | shift+=1 16 | array[j] = temp 17 | comparison+=1 18 | print("Array after ",times,"th pass is : ",array) 19 | gap = gap//2 20 | print("Array after sorting is : ",array) 21 | print(shift," number of shift and",comparison," comparisons") 22 | 23 | def input_array(): #function for taking input of array 24 | attended=[] 25 | number_of_attendee=int(input("Enter number of attendee : ")) 26 | for i in range(number_of_attendee): 27 | tep=int(input("Enter roll number of attendee:")) 28 | attended.append(tep) 29 | return attended 30 | 31 | if __name__ == '__main__': 32 | arr=input_array() 33 | shell_sort(arr) 34 | print("Array after sorting using shell sort : ",arr) -------------------------------------------------------------------------------- /SortingAlgorithms/python/bubbleSort.py: -------------------------------------------------------------------------------- 1 | def bubblesort(list): 2 | 3 | for iter_num in range(len(list)-1,0,-1): 4 | for idx in range(iter_num): 5 | if list[idx]>list[idx+1]: 6 | temp = list[idx] 7 | list[idx] = list[idx+1] 8 | list[idx+1] = temp 9 | 10 | 11 | list = [19,2,31,45,6,11,121,27] 12 | bubblesort(list) 13 | print(list) -------------------------------------------------------------------------------- /SortingAlgorithms/python/insertion sort.py: -------------------------------------------------------------------------------- 1 | def insertion_sort(array): #function to sort array using insertion sort 2 | comparison=0 3 | shift=0 4 | for i in range(1,len(array)): 5 | j=i-1 6 | val=array[i] 7 | while(j>=0 and valarray[j]): 10 | swaps+=1 11 | isSwap=True 12 | temp=array[j] 13 | array[j]=array[j-1] 14 | array[j-1]=temp 15 | comparison+=1 16 | print("Array after ",i+1,"th pass is : ",array) 17 | i+=1 18 | print("Array after sorting is : ",array) 19 | print(swaps," number of swaps and",comparison," comparisons") 20 | 21 | def input_array(): #function for taking input of array 22 | attended=[] 23 | number_of_attendee=int(input("Enter total : ")) 24 | for i in range(number_of_attendee): 25 | tep=int(input("Enter number :")) 26 | attended.append(tep) 27 | return attended 28 | 29 | if __name__ == '__main__': 30 | arr=input_array() 31 | optimised_bubble_sort(arr) 32 | print("Array after sorting using selection sort : ",arr) 33 | -------------------------------------------------------------------------------- /StairCaseProblem/C++/stair.cpp: -------------------------------------------------------------------------------- 1 | 2 | //DP solution to staircase problem Time Complexity : O(n) 3 | 4 | #include 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | 9 | const int size = 1e6; 10 | ll dp[size]; 11 | 12 | ll noofWays( int n){ 13 | 14 | if(n==1){ 15 | return 1; 16 | } 17 | if(n==2){ 18 | return 2; 19 | } 20 | if(n==3){ 21 | return 4; 22 | } 23 | 24 | dp[0] = 0; 25 | dp[1] = 1; 26 | dp[2] = 2; 27 | dp[3] = 4; 28 | for(int i=4;i<=n;i++){ 29 | dp[i] = dp[i-1] + dp[i-2] + dp[i-3]; 30 | } 31 | 32 | return dp[n]; 33 | } 34 | 35 | int main() 36 | { 37 | int n; 38 | cin>>n; 39 | 40 | 41 | 42 | cout< 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | double calculateStandardDeviation(vector arr) 14 | { 15 | //Calculate the mean 16 | double mean = 0; 17 | for(int i=0;i> size; 37 | vector arr; 38 | int x; 39 | while(cin >> x) 40 | { 41 | arr.push_back(x); 42 | } 43 | 44 | cout << fixed << setprecision(1) << calculateStandardDeviation(arr) << endl; 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /SubsetSum/CPP/SubsetSum.cpp: -------------------------------------------------------------------------------- 1 | //Code for finding if a number can be formed by adding all 2 | // elements of any subset of given list of numbers 3 | // of a given list 4 | #include 5 | using namespace std; 6 | bool isSubsetSumPossible(int n, vector &a, int sum) 7 | { 8 | vector> dp(n + 1, vector(sum + 1, false)); 9 | int i, j; 10 | for (i = 0; i <= n; i++) 11 | dp[i][0] = true; 12 | for (i = 1; i <= n; i++) 13 | { 14 | for (j = 1; j <= sum; j++) 15 | { 16 | dp[i][j] = dp[i - 1][j]; 17 | if (j >= a[i - 1]) 18 | dp[i][j] = dp[i][j] || dp[i - 1][j - a[i - 1]]; 19 | } 20 | } 21 | return dp[n][sum]; 22 | } 23 | 24 | int main() 25 | { 26 | int n; 27 | cin >> n; 28 | vector nums(n, 0); 29 | int i; 30 | for (i = 0; i < n; i++) 31 | cin >> nums[i]; 32 | int sum; 33 | cin >> sum; 34 | if (isSubsetSumPossible(n, nums, sum)) 35 | cout << "Subset formation with given sum is possible"; 36 | else 37 | cout << "Subset formation with given sum is not possible"; 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /SumOf_n^2/C++/SumOf_n^2.C++: -------------------------------------------------------------------------------- 1 | /*Method:- 2 | Sum of square of first N natural number = (N * (N + 1) * (2*N + 1)) / 6; 3 | exmple:- 4 | For N =4, Sum = (4 * (4 + 1) * (2 * 4 + 1)) /6; 5 | = (4*5*9)/6 6 | =180/6 7 | = 30 8 | 9 | For N =5, Sum = (5 * (5 + 1) * (2 * 5 + 1)) /6; 10 | = (5*6*11)/6 11 | = 55 */ 12 | 13 | // CPP Program to find sum 14 | // of square of first n 15 | // natural numbers 16 | #include 17 | using namespace std; 18 | 19 | // Return the sum of square of 20 | // first n natural numbers 21 | int squaresum(int n) 22 | { 23 | return (n * (n + 1) * (2 * n + 1)) / 6; 24 | } 25 | 26 | // Driven Program 27 | int main() 28 | { 29 | int n = 4; 30 | cout << squaresum(n) << endl; 31 | return 0; 32 | } 33 | 34 | /*Output: 35 | 36 | 30 */ -------------------------------------------------------------------------------- /SumOfcubes/C++/SumOfcubes.C++: -------------------------------------------------------------------------------- 1 | 2 | // CPP Program to find sum of cubes of first n natural numbers 3 | #include 4 | using namespace std; 5 | 6 | int sumofcubes(int n) 7 | { 8 | return (n * (n + 1) /2) * (n * (n + 1) /2); 9 | } 10 | 11 | 12 | int main() 13 | { 14 | int n = 5; 15 | cout << sumofcubes(n) << endl; 16 | return 0; 17 | } 18 | 19 | /*Output: 225 */ 20 | -------------------------------------------------------------------------------- /SwappingOfNumbers/C++/CyclicOrderUsingCallByReference.C++: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void cyclicSwap(int *a, int *b, int *c); 5 | 6 | int main() 7 | { 8 | int a, b, c; 9 | 10 | cout << "Enter value of a, b and c respectively: "; 11 | cin >> a >> b >> c; 12 | 13 | cout << "Value before swapping: " << endl; 14 | cout << "a, b and c respectively are: " << a << ", " << b << ", " << c << endl; 15 | 16 | cyclicSwap(&a, &b, &c); 17 | 18 | cout << "Value after swapping numbers in cycle: " << endl; 19 | cout << "a, b and c respectively are: " << a << ", " << b << ", " << c << endl; 20 | 21 | return 0; 22 | } 23 | 24 | void cyclicSwap(int *a, int *b, int *c) 25 | { 26 | int temp; 27 | temp = *b; 28 | *b = *a; 29 | *a = *c; 30 | *c = temp; 31 | } -------------------------------------------------------------------------------- /TowerOfHanoi/hanoi.py: -------------------------------------------------------------------------------- 1 | def TOH(n, S, M, D): 2 | if(n==1): 3 | print("Move disk {} from {} to {}".format(n,S,D)) 4 | return 0 5 | TOH( n-1, S, D, M) 6 | print("Move disk {} from {} to {}".format(n,S,D)) 7 | TOH(n-1, M, S, D) 8 | 9 | 10 | print("Enter no. of disks") 11 | n = int(input()) 12 | TOH(n,'A','B','C') 13 | -------------------------------------------------------------------------------- /TowerOfHanoi/tower_of_hanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void tower(int n,char *source,char *helper, char *destination) 4 | { 5 | //base case 6 | if(n==0) 7 | { 8 | return; 9 | } 10 | tower(n-1,source,destination,helper); // We will put n-1 disks in helper with the help of destination 11 | cout<<"taking "<>n; 19 | char source[10]="T1",helper[10]="T2",destination[10]="T3"; 20 | tower(n,source,helper,destination); 21 | } 22 | -------------------------------------------------------------------------------- /Vector(STL)/Question.md: -------------------------------------------------------------------------------- 1 | # Sort a vector 2 | 3 | You are given *N* integers. Sort the *N* integers and print the sorted order. 4 | Store the *N* integers in a vector. Vectors are sequence containers representing arrays that can change in size. 5 | 6 | ## Constraints 7 | 8 | - 1 <= N <= 100000 9 | - 1 <= V[i] <= 100000000, Where Vi is the ith integer in the vector. 10 | 11 | ## Sample Input 12 | 13 | 5 14 | 15 | 1 6 10 8 4 16 | 17 | ## Sample Output 18 | 19 | 1 4 6 8 10 20 | -------------------------------------------------------------------------------- /Vector(STL)/VectorSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int ele; 10 | vector v; 11 | int x; 12 | cin>>x; 13 | for(int i=0;i>ele; 16 | v.push_back(ele); 17 | } 18 | sort(v.begin(),v.end()); 19 | for(int i=0;i 2 | using namespace std; 3 | 4 | 5 | int z[100500]; 6 | string str; 7 | 8 | void fillZ() { 9 | int n = sz(str); 10 | int l, r; 11 | l = r = 0; 12 | for (int i = 1; i < n; i++) { 13 | if (i > r) { 14 | l = r = i; 15 | while (r < n && str[r] == str[r - l]) 16 | r++; 17 | r--; 18 | z[i] = r - l + 1; 19 | } else { 20 | int k = i - l; 21 | if (z[k] < r - i + 1) 22 | z[i] = z[k]; 23 | else { 24 | while (r < n && str[r] == str[r - l]) 25 | r++; 26 | r--; 27 | z[i] = r - l + 1; 28 | } 29 | } 30 | } 31 | } 32 | int main() { 33 | string state, patt; 34 | cin >> state >> patt; 35 | str = patt + "%" + state; 36 | fillZ(); 37 | for (int i = 0; i < sz(str); i++) 38 | if (z[i] == sz(patt)) 39 | cout << i - sz(patt) - 1 << endl; 40 | 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /assembly.s: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | .globl main 5 | 6 | .data 7 | 8 | prompt: .asciiz "Please enter a positive integer: " 9 | result1: .asciiz "The sum of the first " 10 | result2: .asciiz " integers is " 11 | newline: .asciiz "\n" 12 | -------------------------------------------------------------------------------- /binary2DecimalBasic.c: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Binary To Decimal Conversion 3 | 4 | Given a binary number as input, we need to write a program to convert the given binary number into an equivalent decimal number. 5 | 6 | Examples : 7 | 8 | Input : 111 9 | Output : 7 10 | 11 | Input : 1010 12 | Output : 10 13 | 14 | Input: 100001 15 | Output: 33 16 | */ 17 | #include 18 | int bin2dec(int num) 19 | { 20 | int dec = 0, base = 1; 21 | while (num != 0) 22 | { 23 | dec = dec + ((num % 10) * base); 24 | base *= 2; 25 | num /= 10; 26 | } 27 | return dec; 28 | } 29 | 30 | int main() 31 | { 32 | 33 | // for test case 34 | int t; 35 | scanf("%d", &t); 36 | 37 | while (t--) 38 | { 39 | // main logic 40 | int num; 41 | scanf("%d", &num); 42 | 43 | printf("%d\n", bin2dec(num)); 44 | } 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /decimal2OctalBasic.c: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Octal Conversion 3 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent octal number. i.e convert the number with base value 10 to base value 8. The base value of a number system determines the number of digits used to represent a numeric value. For example, the binary number system uses two digits 0 and 1, octal number system uses 8 digits from 0-7 and decimal number system uses 10 digits 0-9 to represent any numeric value. 4 | 5 | Examples: 6 | 7 | Input : 16 8 | Output : 20 9 | 10 | Input : 10 11 | Output : 12 12 | 13 | Input: 33 14 | Output: 41 15 | 16 | Time Complexity: O(log N) 17 | */ 18 | 19 | #include 20 | 21 | void dec2Octal(int num) 22 | { 23 | int octalNum[100]; 24 | 25 | int i = 0; 26 | while (num != 0) 27 | { 28 | octalNum[i++] = num % 8; 29 | num = num / 8; 30 | } 31 | 32 | for (int j = i - 1; j >= 0; j--) 33 | printf("%d", octalNum[j]); 34 | 35 | printf("\n"); 36 | } 37 | 38 | int main() 39 | { 40 | int t; 41 | scanf("%d", &t); 42 | 43 | while (t--) 44 | { 45 | int num; 46 | scanf("%d", &num); 47 | dec2Octal(num); 48 | } 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /decimal2binaryBasicVoid.c: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Binary Conversion 3 | 4 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. 5 | 6 | Examples: 7 | 8 | Input : 7 9 | Output : 111 10 | 11 | Input : 10 12 | Output : 1010 13 | 14 | Input: 33 15 | Output: 100001 16 | */ 17 | #include 18 | void dec2bin(int num) 19 | { 20 | int str[32]; 21 | if (num == 0) 22 | { 23 | printf("0\n"); 24 | return; 25 | } 26 | 27 | int i = 0; 28 | 29 | while (num > 0) 30 | { 31 | str[i] = num % 2; 32 | num = num / 2; 33 | ++i; 34 | } 35 | 36 | for (int j = i - 1; j >= 0; --j) 37 | printf("%d", str[j]); 38 | 39 | printf("\n"); 40 | } 41 | 42 | int main() 43 | { 44 | int t; 45 | scanf("%d\n", &t); 46 | 47 | while (t--) 48 | { 49 | int num; 50 | scanf("%d", &num); 51 | 52 | dec2bin(num); 53 | } 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /decimal2binaryUsingBitwise.c: -------------------------------------------------------------------------------- 1 | /* 2 | # Program for Decimal to Binary Conversion 3 | 4 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. 5 | 6 | Examples: 7 | 8 | Input : 7 9 | Output : 111 10 | 11 | Input : 10 12 | Output : 1010 13 | 14 | Input: 33 15 | Output: 100001 16 | */ 17 | #include 18 | void dec2bin(int num) 19 | { 20 | for (int i = 31; i >= 0; --i) 21 | { 22 | int k = num >> i; 23 | if (k & 1) 24 | printf("1"); 25 | else 26 | { 27 | printf("0"); 28 | } 29 | } 30 | printf("\n"); 31 | } 32 | 33 | int main() 34 | { 35 | int t; 36 | scanf("%d\n", &t); 37 | 38 | while (t--) 39 | { 40 | int num; 41 | scanf("%d", &num); 42 | 43 | if (num == 0) 44 | { 45 | printf("0\n"); 46 | continue; 47 | } 48 | 49 | dec2bin(num); 50 | } 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /docker/flask/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7-alpine 2 | WORKDIR /code 3 | ENV FLASK_APP app.py 4 | ENV FLASK_RUN_HOST 0.0.0.0 5 | RUN apk add --no-cache gcc musl-dev linux-headers 6 | COPY requirements.txt requirements.txt 7 | RUN pip install -r requirements.txt 8 | EXPOSE 5000 9 | COPY . . 10 | CMD ["flask", "run"] -------------------------------------------------------------------------------- /docker/flask/app.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import redis 4 | from flask import Flask 5 | 6 | app = Flask(__name__) 7 | cache = redis.Redis(host='redis', port=6379) 8 | 9 | 10 | def get_hit_count(): 11 | retries = 5 12 | while True: 13 | try: 14 | return cache.incr('hits') 15 | except redis.exceptions.ConnectionError as exc: 16 | if retries == 0: 17 | raise exc 18 | retries -= 1 19 | time.sleep(0.5) 20 | 21 | 22 | @app.route('/') 23 | def hello(): 24 | count = get_hit_count() 25 | return 'Hello World! I have been seen {} times.\n'.format(count) -------------------------------------------------------------------------------- /docker/flask/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | web: 4 | build: . 5 | ports: 6 | - "5000:5000" 7 | redis: 8 | image: "redis:alpine" -------------------------------------------------------------------------------- /docker/flask/requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | redis -------------------------------------------------------------------------------- /hackerrank/Aray/2D_array.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | int a[100][100], max = -324, temp, b[100]; 8 | 9 | for ( int i=0; i<6; i++ ) { 10 | for ( int j=0; j<6; j++ ) { 11 | cin >> a[i][j]; 12 | } 13 | } 14 | 15 | for ( int i=0; i<4; i++ ) { // input matrix is 6x6 and our stride is 3x3, so inorder to cover the whole are we can move at most 4 steps 16 | for ( int j=0; j<4; j++ ) { // rigth and 4 steps down so here i and j is 0 - 3 17 | temp = a[i][j] + a[i][j+1] + a[i][j+2] + a[i+1][j+1] + a[i+2][j] + a[i+2][j+1] + a[i+2][j+2] ; // this are the position of the matrix we need to clculate 18 | 19 | if ( temp > max ) { //every time we will store the max value compareing to the privous 20 | max = temp; 21 | } 22 | } 23 | } 24 | cout << max << endl; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /hackerrank/FibonacciNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | # The Fibonacci Sequence 3 | 4 | The Fibonacci sequence appears in nature all around us, in the arrangement of seeds in a sunflower and the spiral of a nautilus for example. 5 | 6 | The Fibonacci sequence begins with and as its first and second terms. After these first two elements, each subsequent element is equal to the sum of the previous two elements. 7 | 8 | Programmatically: 9 | 10 | Given , return the number in the sequence. 11 | 12 | As an example, . The Fibonacci sequence to is . With zero-based indexing, . 13 | 14 | Function Description 15 | 16 | Complete the recursive function in the editor below. It must return the element in the Fibonacci sequence. 17 | 18 | fibonacci has the following parameter(s): 19 | 20 | n: the integer index of the sequence to return 21 | Input Format 22 | The input line contains a single integer. 23 | 24 | Output Format 25 | Locked stub code in the editor prints the integer value returned by the function. 26 | 27 | Sample Input 28 | 3 29 | 30 | Sample Output 31 | 2 32 | */ 33 | import java.util.*; 34 | 35 | public class Solution { 36 | 37 | public static int fibonacci(int n) { 38 | if(n < 1) 39 | return 0; 40 | if(n == 1) 41 | return 1; 42 | return fibonacci(n-1) + fibonacci(n-2); 43 | } 44 | 45 | 46 | public static void main(String[] args) { 47 | Scanner scanner = new Scanner(System.in); 48 | int n = scanner.nextInt(); 49 | scanner.close(); 50 | System.out.println(fibonacci(n)); 51 | } 52 | } -------------------------------------------------------------------------------- /hackerrank/FibonacciNumbers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | # The Fibonacci Sequence 3 | 4 | The Fibonacci sequence appears in nature all around us, in the arrangement of seeds in a sunflower and the spiral of a nautilus for example. 5 | 6 | The Fibonacci sequence begins with and as its first and second terms. After these first two elements, each subsequent element is equal to the sum of the previous two elements. 7 | 8 | Programmatically: 9 | 10 | Given , return the number in the sequence. 11 | 12 | As an example, . The Fibonacci sequence to is . With zero-based indexing, . 13 | 14 | Function Description 15 | 16 | Complete the recursive function in the editor below. It must return the element in the Fibonacci sequence. 17 | 18 | fibonacci has the following parameter(s): 19 | 20 | n: the integer index of the sequence to return 21 | Input Format 22 | The input line contains a single integer. 23 | 24 | Output Format 25 | Locked stub code in the editor prints the integer value returned by the function. 26 | 27 | Sample Input 28 | 3 29 | 30 | Sample Output 31 | 2 32 | */ 33 | #include 34 | 35 | using namespace std; 36 | 37 | int fibonacci(int n) { 38 | // Complete the function. 39 | if(n < 1) 40 | return 0; 41 | if(n == 1) 42 | return 1; 43 | return fibonacci(n-1)+fibonacci(n-2); 44 | } 45 | 46 | int main() { 47 | int n; 48 | cin >> n; 49 | cout << fibonacci(n); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /hackerrank/vector/imakshat47_vectorSort.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Vector-Sort 3 | Sample Input 4 | 5 5 | 1 6 10 8 4 6 | Sample Output 7 | 1 4 6 8 10 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | int n; 20 | scanf("%d", &n); 21 | 22 | vector vec(n); 23 | 24 | for (int i = 0; i < n; ++i) 25 | { 26 | scanf("%d", &vec[i]); 27 | } 28 | 29 | sort(vec.begin(), vec.end()); 30 | 31 | // To print values in vector 32 | for (auto i : vec) 33 | { 34 | printf("%d ", i); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /img/Anjali.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/Anjali.jpeg -------------------------------------------------------------------------------- /img/AswinCG2002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/AswinCG2002.jpg -------------------------------------------------------------------------------- /img/Cuncis.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/Cuncis.jpeg -------------------------------------------------------------------------------- /img/DeepamPriyadarshi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/DeepamPriyadarshi.jpg -------------------------------------------------------------------------------- /img/Ishika.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/Ishika.jpg -------------------------------------------------------------------------------- /img/Jay_Shukla.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/Jay_Shukla.jpg -------------------------------------------------------------------------------- /img/Kunal888.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/Kunal888.jpg -------------------------------------------------------------------------------- /img/NishantBhatia.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/NishantBhatia.jpeg -------------------------------------------------------------------------------- /img/Vishi13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/Vishi13.jpg -------------------------------------------------------------------------------- /img/ashfaqahmed.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/ashfaqahmed.jpg -------------------------------------------------------------------------------- /img/cedric-img-portrait-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/cedric-img-portrait-2.png -------------------------------------------------------------------------------- /img/rahul.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/rahul.jpeg -------------------------------------------------------------------------------- /img/rajarshi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/rajarshi.jpg -------------------------------------------------------------------------------- /img/sai_pranay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/sai_pranay.jpg -------------------------------------------------------------------------------- /img/zahinekbal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zahinekbal/codeWith-hacktoberfest/2e6dc7a63cb1097b6017643ed18e29eb957d49a4/img/zahinekbal.jpg -------------------------------------------------------------------------------- /isUnique/isUnique.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | string str; 6 | cout<<"Enter a string\n"; 7 | cin>>str; 8 | int flag=0; 9 | vector freq(128,false); 10 | for(int i=0;i 8 | using namespace std; 9 | 10 | // This function returns value of (x^y)%mod. 11 | int power(int x, int y, int mod) 12 | { 13 | int answer = 1; // Initialise the answer 14 | 15 | x = x % mod; 16 | 17 | if(x == 0) return 0; // If x is divisible by mod 18 | 19 | while(y > 0) 20 | { 21 | if(y % 2 == 1) // If y is odd multiply x with answer 22 | { 23 | answer = (answer*x) % mod; 24 | } 25 | 26 | y /= 2; // reduce the value of y 27 | x = (x*x) % mod; // increment the value of x 28 | } 29 | 30 | return answer; 31 | } 32 | 33 | 34 | // Main function 35 | int main() 36 | { 37 | int x = 2, y = 10, mod = 1000000007; 38 | int result = power(x, y, mod); 39 | cout << result << '\n'; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /octal2binary.c: -------------------------------------------------------------------------------- 1 | // # Write a program to convert Octal to Binary 2 | /* 3 | Examples: 4 | 5 | Input : 25 6 | Output : 10101 7 | 8 | Input : 51 9 | Output : 101001 10 | 11 | Input: 5 12 | Output: 101 13 | */ 14 | 15 | #include 16 | 17 | int octal2bin(int octal) 18 | { 19 | int dec = 0, base = 1; 20 | 21 | while (octal != 0) 22 | { 23 | dec += (octal % 10) * base; 24 | base *= 8; 25 | octal /= 10; 26 | } 27 | 28 | int bin = 0; 29 | base = 1; 30 | 31 | while (dec != 0) 32 | { 33 | bin += ((dec % 2) * base); 34 | base *= 10; 35 | dec /= 2; 36 | } 37 | 38 | return bin; 39 | } 40 | 41 | int main() 42 | { 43 | int t; 44 | scanf("%d", &t); 45 | 46 | while (t--) 47 | { 48 | int num; 49 | scanf("%d", &num); 50 | printf("%d\n", octal2bin(num)); 51 | } 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /python/Checking-Prime-Number.py: -------------------------------------------------------------------------------- 1 | # Program to check whether a number is prime number or not 2 | 3 | # To take input from the user 4 | number = int(input("Enter the number: ")) 5 | 6 | # prime numbers are greater than 1 7 | if number > 1: 8 | # check for factors 9 | for i in range(2,number): 10 | if (number % i) == 0: 11 | print(f"The given number {number} is not a prime number") 12 | break 13 | else: 14 | print(f"The given number {number} is a prime number") 15 | 16 | # if the given input number is less than or equal to 1, it is not prime. 17 | # So we are giving an else condition. 18 | 19 | else: 20 | print(num,"is not a prime number") 21 | 22 | -------------------------------------------------------------------------------- /python/Factorial-of-a-number-in-Python.py: -------------------------------------------------------------------------------- 1 | # Python program to find the factorial of a number. 2 | 3 | #To take the number, input from the user 4 | number = int(input("Enter the number: ")) 5 | 6 | # Assigning 1 to a variable named 'factorial'. 7 | # The factorial value will be stored inside this variable 8 | factorial = 1 9 | 10 | # To check whether the number is negative, positive or zero. 11 | 12 | # To check whther the number is negative 13 | if number < 0: 14 | print("Sorry, factorial does not exist for negative numbers") 15 | 16 | # To check whether the input number is zero 17 | elif number == 0: 18 | print("The factorial of 0 is 1") 19 | 20 | # If both the above conditions fails then the number is a positive integer. 21 | else: 22 | for i in range(1,number + 1): 23 | factorial = factorial*i 24 | print(f"The factorial of the number {number} is: {factorial}") 25 | -------------------------------------------------------------------------------- /python/JadooAndDNATranscription.py: -------------------------------------------------------------------------------- 1 | # Jadoo, the Space Alien has befriended Koba upon landing on Earth. Since then, he wishes Koba to be more like him. In order to do so he decides to slowly transcribe Koba's DNA into RNA. But he has to write a very short code in order to do the transcription so as not to make Koba aware of the change. 2 | 3 | # The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T). 4 | 5 | # The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U). 6 | 7 | # Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement: 8 | 9 | # G --> C 10 | # C --> G 11 | # T --> A 12 | # A --> U 13 | 14 | 15 | # Input: The input will always be a string of characters. 16 | 17 | # Output: The output should always be a string of characters. In the case of invalid input, you should output Invalid Input as a string. 18 | 19 | # Rules: Your code should not consist of any numerical characters (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and the length of your code should be <= 103. If your code consists of numerical characters, then your score is zero irrespectuve of your code length or testcases satisfied. If your code is devoid of numerical characters and is of length > 103 then you score 50%. 20 | 21 | 22 | # Write your code here 23 | string = input() 24 | flag = True 25 | out = '' 26 | for s in string: 27 | if s == 'A': 28 | out += 'U' 29 | elif s == 'G': 30 | out += 'C' 31 | elif s == 'C': 32 | out += 'G' 33 | elif s == 'T': 34 | out += 'A' 35 | else: 36 | flag = False 37 | 38 | if flag: 39 | print(out) 40 | else: 41 | print("Invalid Input") 42 | -------------------------------------------------------------------------------- /python/telegrambot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | #simple Telegram Bot To Say Hi Hello 3 | from telegram.ext import Updater, CommandHandler, MessageHandler 4 | import requests 5 | 6 | 7 | def start(update, context): 8 | response = "Hello I am a Test Bot How are you ? 😄😄" 9 | update.message.reply_text(response, parse_mode= "HTML") 10 | 11 | def hello(update, context): 12 | update.message.reply_text( 13 | 'Hello {}😄😄, How ya been ?'.format(update.message.from_user.id,update.message.from_user.first_name), parse_mode= "HTML") 14 | 15 | def me (update, context): 16 | update.message.reply_text( 17 | 'Extracted From Megik Db \n Your name : {} \nIs a Bot : {} 😶😶\n'.format(update.message.from_user.id,update.message.from_user.full_name,update.message.from_user.is_bot), parse_mode= "HTML") 18 | 19 | 20 | 21 | 22 | 23 | #token 24 | updater = Updater('', use_context=True) 25 | 26 | 27 | updater.dispatcher.add_handler(CommandHandler('hi', start)) 28 | updater.dispatcher.add_handler(CommandHandler('hello', hello)) 29 | updater.dispatcher.add_handler(CommandHandler('about', me)) 30 | 31 | updater.start_polling() 32 | updater.idle() 33 | --------------------------------------------------------------------------------