├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── HackerRank └── README.md ├── LICENSE ├── Lectures ├── CS97SISlides │ ├── 01-introduction.pdf │ ├── 02-mathematics.pdf │ ├── 03-data-structures.pdf │ ├── 04-dynamic-programming.pdf │ ├── 05-combinatorial-games.pdf │ ├── 06-basic-graph-algorithms.pdf │ ├── 07-shortest-path-algorithms.pdf │ ├── 08-network-flow-problems.pdf │ ├── 09-computational-geometry.pdf │ ├── 10-string-algorithms.pdf │ └── suffix-array.pdf ├── Lecture17.md ├── README.md ├── amazon.md └── data-structures │ ├── Lecture01.md │ ├── Lecture02-1.md │ ├── Lecture02-2.md │ ├── Lecture02.md │ ├── Lecture03.md │ ├── Lecture04.md │ ├── Lecture05.md │ ├── Lecture06.md │ ├── Lecture07.md │ ├── Lecture09.md │ ├── Lecture10.md │ ├── Lecture11.md │ ├── Lecture12.md │ ├── Lecture13.md │ ├── Lecture14.md │ ├── Lecture15.md │ ├── Lecture16.md │ └── Lecture20.md ├── Leetcode ├── README.md ├── REPLACE-ELEMENT-WITH-greater-on-right-side.cpp ├── average-of-levels-in-binary-tree.cpp ├── average-salary-excluding-min-and-max.cpp ├── average-salary.py ├── big-countries.sql ├── binary-number-with-alternating-bits.cpp ├── binary-search.cpp ├── binary-tree-inorder.cpp ├── binary-tree-level-order-traversal-ii.cpp ├── binary-tree-level-order-traversal.cpp ├── binary-tree-preorder-traversal.cpp ├── check-if-a-number-is-majority-element-in-a-sorted-array.cpp ├── check-if-a-tree-is-a-bst.cpp ├── check-if-n-and-its-double-exists.cpp ├── contains-duplicate.cpp ├── contains_duplicate.py ├── convert-binary-number-in-a-inked-list.cpp ├── count-negative-numbers-in-a-sorted-matrix.cpp ├── count-number-of-teams.cpp ├── countOdds.py ├── count_odds_in_number_interval.cpp ├── counting-bits.cpp ├── create-targe-array-in-the-given-order.cpp ├── day-of-the-week.cpp ├── defaining-an-ip.cpp ├── detect-capital.cpp ├── element-appearing-more-than-25-in-sorted-array.cpp ├── final-prices-with-a-special-discount-in-a-shop.cpp ├── find-all-duplicates-in-an-array.cpp ├── find-duplicate.cpp ├── find-largest-value-in-each-tree-row.cpp ├── find-numbers-with-even-digits.cpp ├── find-peak-element-facebook.cpp ├── find-peak-element.cpp ├── find-the-difference.cpp ├── find-the-duplicate-number.cpp ├── find_pivot_index.cpp ├── first-last-index-of-an-element.cpp ├── first-unique-character.cpp ├── fizz-buzz.cpp ├── fun-with-arays.cpp ├── how-many-numbers-are-smaller-then-current-number.cpp ├── implement-queue-suing-stacks.cpp ├── invalid-tweets.sql ├── jewels-and-stones.cpp ├── kids-with-the-greatest-number-of-candies.cpp ├── kth-larghest-element0-in-an-array.cpp ├── larghest-unique-number.cpp ├── lca-of-binary-tree.cpp ├── length-of-last-word.cpp ├── linked-list-cycle.cpp ├── lucky_number_in_an_array.cpp ├── majority-element.cpp ├── matrix-diagonal-sum.cpp ├── max-consecutive-onse.cpp ├── max-depth-of-binary-tree.cpp ├── maximum-69-number.cpp ├── maximum-count-of-positive-integer-and-negative-integer.cpp ├── maximum-product-of-two-elements-in-an-array.cpp ├── median-of-two-sorted-arrays.cpp ├── merge-sorted-array.cpp ├── middle-of-linked-list.cpp ├── missing-number.cpp ├── morris.cpp ├── most-common-word.cpp ├── move-zeros.cpp ├── n-repeated-element-in-size-2n-array.cpp ├── no_of_provinces.cpp ├── number-of-1-bits.cpp ├── number-of-islands.cpp ├── number-of-students-doing-homework-at-a-given-time.cpp ├── number_of_good_pairs.cpp ├── palindrome-linked-list.cpp ├── palindrome.cpp ├── postorder-tree.cpp ├── power-of-tree.cpp ├── power-of-two.cpp ├── range-sum-of-bst.cpp ├── recyclable-and-low-fat-products.sql ├── remove-duplicates-from-array.cpp ├── remove-duplicates-from-linked-list.cpp ├── remove-vowels-from-a-string.cpp ├── replace_element.cpp ├── reverse-integer.cpp ├── reverse-linked-list.cpp ├── reverse-only-letters.cpp ├── reverse-string.cpp ├── reverse-vowels-of-a-string.cpp ├── reverse-words-in-a-string-iii.cpp ├── reverse-words-in-a-string.cpp ├── reverse_string2.cpp ├── richest-customer-wealth.cpp ├── running-sum-of-1d-array.cpp ├── search-2d-matrix.cpp ├── search-in-a-rotated-sorted-array.cpp ├── search-in-binary-search-tree.cpp ├── search-in-rotated-sorted-array-ii.cpp ├── search-in-rotated-sorted-array.cpp ├── search-insert-position.cpp ├── self-dividing-numbers.cpp ├── shaffle_the_array.cpp ├── singleNumber.cpp ├── single_number_III.cpp ├── sort-an-array.cpp ├── sort-array-by-parity-ii.cpp ├── sort-array-by-parity.cpp ├── sort_colors.cpp ├── squares-of-a-sorted-array.cpp ├── subtract-the-product-and-sum-of-digits-of-an-integer.cpp ├── sudoku_sol.cpp ├── sum-of-digits-in-the-minimum-number.cpp ├── sum_two_linked_list.cpp ├── swap-nodes-in-pairs.cpp ├── thread_python.py ├── three-consecutive-odds.cpp ├── to-lower-case.cpp ├── two-sum.cpp ├── two_sum.py ├── unique-number-of-occurrences.cpp ├── valid-anagram.cpp ├── valid-palindrome.cpp ├── valid-parentheses └── vertical_trav.cpp ├── MUST_KNOW_ALGORITHMS.md ├── README.md ├── Reading ├── 2008_Book_AlgorithmsAndDataStructures.pdf ├── 2009_Book_AConciseAndPracticalIntroducti.pdf ├── 2015_Book_DataStructuresAndAlgorithmsWit.pdf ├── 2019_Book_JavaScriptDataStructuresAndAlg.pdf ├── 5 Algorithm Analysis.pdf ├── Competitive Programming 3.pdf ├── CompetitiveProgrammerHandbook.pdf ├── Cracking-the-Coding-Interview-6th-Edition.pdf ├── Introduction_to_algorithms-3rd Edition.pdf ├── Stacks Queues Priority Queues.pdf └── cp1.pdf ├── UVA ├── 11727CostCutting.cpp ├── 12289_OneTwoThree.cpp ├── 12372PackForHoliday.cpp ├── 12403SaveShetu.cpp ├── 12577Hajj_e_Akbar.cpp ├── UVA01124.cpp ├── UVA11172.cpp └── UVa11942LumberjackSequencing.cpp ├── algorithm ├── a.out ├── generate-sub-arrays │ ├── a.out │ ├── iterative-subarray-generator.cpp │ └── store-all-sbuarrays.cpp ├── kadane_s_algorithm.cpp └── kadanes_NEGATIVE_numbers.cpp ├── books ├── Programming Interviews Exposed ( PDFDrive.com ).pdf └── htaph_theory.pdf ├── codebyte ├── README.md ├── longest_word │ └── longest_word.java ├── prime_factorial │ └── prime_factorial.java └── reverse │ └── reverse.java ├── codechef ├── ADASCOOL.c ├── ATM2.c ├── AVG.c ├── BALLBOX.cpp ├── BROKENPHONE.cpp ├── BROKPHON.c ├── CABS.cpp ├── CHFNSWAP.cpp ├── DOLL.cpp ├── EXAMTIME.c ├── FEVER.cpp ├── HOWMANYMAX.c ├── LONGSEQ.cpp ├── MATCHES.cpp ├── PRACTICEPERF.cpp ├── PROGLANG.c ├── README.md ├── TLG.cpp ├── VOLCONTROL.cpp ├── ZOOZ.c ├── arm15a.cpp ├── atm.py ├── atm_machine.cpp ├── blackcel.py ├── buying-new-tables.cpp ├── carvans.cpp ├── chef-and-snackdown.cpp ├── choprt.cpp ├── devu_and_friendship_testing.cpp ├── factorial.cpp ├── fctrl2.cpp ├── flow002.cpp ├── flow004.cpp ├── flow006.cpp ├── flow008.cpp ├── flow018.cpp ├── flow17.cpp ├── fsqrt.cpp ├── gross_salary.py ├── how-many-digits-do-i-have.cpp ├── how_much_scolariship.cpp ├── increment_or_decrement.cpp ├── intest.cpp ├── is_it_vowel_or_consonant.cpp ├── luckfour.cpp ├── magic-element.cpp ├── mutated-minions.cpp ├── pall01.cpp ├── pretty_number.cpp ├── prim1.cpp ├── primality-test.cpp ├── process-a-string.cpp ├── reverse_the_number.cpp ├── start01.cpp ├── sum_two_number.cpp ├── tanu-head-bob.cpp ├── that-is-my-score.cpp ├── the-smallest-pair.cpp ├── total_expenses.py └── turboSort.cpp ├── codeforce ├── README.md ├── a.out ├── bit++.cpp ├── boy_or_girl.cpp ├── bst-operations.cpp └── string_task.cpp ├── codesignal ├── README.md ├── add_border.cpp ├── add_two_digits.cpp ├── adjacency-max-product.cpp ├── all_longest_string.cpp ├── alternating-sum.cpp ├── candies.cpp ├── century-from-year.cpp ├── check-palindrome.cpp ├── codewriting.cpp ├── common_character_count.cpp ├── contains_duplicates.cpp ├── first-duplicate.cpp ├── first-non-repeating-char.cpp ├── is_linked_list_palindrome.cpp ├── larghest_number.cpp ├── max_multiple ├── missing_number.cpp ├── seats_in_threatrer ├── shapeArea.cpp └── third_number.cpp ├── codingblock ├── Manmohan-Loves-Patterns-I.cpp ├── README.md ├── binary-to-decimal.cpp ├── check-prime.cpp ├── gdc.cpp ├── geekforgeeks │ └── README.md ├── hello-codingblocks.cpp ├── help_raul.cpp ├── lower-Upper.cpp ├── make-them-distinct.cpp ├── max-after-m-increments.cpp ├── odd-and-even-back-in-Delhi.cpp ├── prime-visits.cpp ├── simple-input.cpp └── von-newumans-love-binary.cpp ├── geeksforgeeks └── README.md ├── hackerearth ├── Little-Jhool-and-psychic-powers.cpp ├── a+b.cpp ├── a-movement.cpp ├── back-to-school.cpp ├── char-sum.cpp ├── determining-numbers.cpp ├── doctor-secret.cpp ├── factorial.cpp ├── i-am-easy.cpp ├── life-universe-everything.cpp ├── mistery.cpp ├── palindrome.cpp ├── repeated-k-times.cpp ├── simple-search.cpp └── two-strings.cpp ├── images ├── Insertion-sort-example.gif ├── bigocomplexity.png ├── bubble-sort.gif ├── complete-tree.jpeg ├── complexity-sort.png ├── complexity.png ├── depency.png ├── deuque.png ├── diameter_of_tree.png ├── fibonacci-heap.png ├── graph.png ├── larghest-sum-contiguos.png ├── lca.png ├── left_view.png ├── lps.png ├── matrices-multiplication.png ├── merge-sort.gif ├── mirror-tree.jpeg ├── perfect-binary-tree.png ├── quick-sort.gif ├── selection-sort.gif ├── sorting-complexity.png ├── spanning-tree-tutorialpoint.png ├── tree-depth.png ├── tree-views.png ├── types-of-edges.png ├── vertical_bt.png └── what.jpeg ├── interviewbit ├── README.md └── learn_data_structures │ ├── c++ │ └── data-structures │ │ ├── ReadMe.md │ │ ├── alphabet_pair.cpp │ │ ├── deque │ │ └── deque.cpp │ │ ├── graph │ │ ├── breath-first-search.cpp │ │ ├── depth-first-search.cpp │ │ ├── detect-cycle.cpp │ │ ├── unweighteGraph.cpp │ │ └── weighted_graph.cpp │ │ ├── linkedList │ │ └── LinkedListIntroduction.cpp │ │ ├── map │ │ └── map_introductionn.cpp │ │ ├── matrix │ │ ├── sumBetweenMatrix.cpp │ │ └── transposted.cpp │ │ ├── occurrency.cpp │ │ ├── queue │ │ └── QueueImplemenentation.cpp │ │ ├── secret_code.cpp │ │ ├── set │ │ └── set.cpp │ │ ├── stack │ │ ├── stack-Linked-list.cpp │ │ └── stack.cpp │ │ └── vectors │ │ ├── PalindromeVector.cpp │ │ ├── VectorIntroductions.cpp │ │ └── two-smallest-in-list.cpp │ ├── c │ ├── HashTable.c │ ├── array.c │ ├── binary_search.c │ ├── challenge1.c │ ├── challenge2.c │ ├── challenge3.c │ ├── challenge4.c │ ├── deque.c │ ├── doubly_linked_list.c │ ├── exponential_search.c │ ├── grades.c │ ├── graph.c │ ├── interpolation_search.c │ ├── jump_search.c │ ├── lab03_data.structures.02.pdf │ ├── lab04_data.structures.03.pdf │ ├── lab05_data.structures.04.pdf │ ├── linear_search.c │ ├── linked_list.c │ ├── main.c │ ├── notes.md │ ├── queue.c │ ├── quicksort.c │ ├── stack.c │ ├── struct.c │ ├── ternary.c │ ├── ternary_search.c │ ├── timing.c │ └── tree.c │ └── python │ ├── algorithm │ └── gcd.py │ ├── array.py │ ├── binarySearchTree.py │ ├── list_methods_implementation.py │ ├── queue.py │ ├── readMe.md │ └── stack.py ├── learn_data_structures ├── c++ │ └── data-structures │ │ ├── ReadMe.md │ │ ├── alphabet_pair.cpp │ │ ├── deque │ │ └── deque.cpp │ │ ├── graph │ │ ├── a.out │ │ ├── breath-first-search.cpp │ │ ├── depth-first-search.cpp │ │ ├── detect-cycle.cpp │ │ ├── unweighteGraph.cpp │ │ └── weighted_graph.cpp │ │ ├── linkedList │ │ └── LinkedListIntroduction.cpp │ │ ├── map │ │ └── map_introductionn.cpp │ │ ├── matrix │ │ ├── sumBetweenMatrix.cpp │ │ └── transposted.cpp │ │ ├── occurrency.cpp │ │ ├── queue │ │ └── QueueImplemenentation.cpp │ │ ├── secret_code.cpp │ │ ├── set │ │ └── set.cpp │ │ ├── stack │ │ ├── stack-Linked-list.cpp │ │ └── stack.cpp │ │ └── vectors │ │ ├── PalindromeVector.cpp │ │ ├── VectorIntroductions.cpp │ │ └── two-smallest-in-list.cpp ├── c │ ├── HashTable.c │ ├── array.c │ ├── binary_search.c │ ├── challenge1.c │ ├── challenge2.c │ ├── challenge3.c │ ├── challenge4.c │ ├── deque.c │ ├── doubly_linked_list.c │ ├── exponential_search.c │ ├── grades.c │ ├── graph.c │ ├── interpolation_search.c │ ├── jump_search.c │ ├── lab03_data.structures.02.pdf │ ├── lab04_data.structures.03.pdf │ ├── lab05_data.structures.04.pdf │ ├── linear_search.c │ ├── linked_list.c │ ├── main.c │ ├── notes.md │ ├── queue.c │ ├── quicksort.c │ ├── stack.c │ ├── struct.c │ ├── ternary.c │ ├── ternary_search.c │ ├── timing.c │ └── tree.c └── python │ ├── algorithm │ └── gcd.py │ ├── array.py │ ├── binarySearchTree.py │ ├── list_methods_implementation.py │ ├── queue.py │ ├── readMe.md │ └── stack.py ├── must-do-exercises ├── README.md ├── arrays │ ├── a.out │ ├── number_of_pairs.cpp │ └── sort-array-of-0-and-1.cpp └── linked-list │ ├── get-middle-element.cpp │ └── nth-node-from-end.cpp ├── spoj ├── 1.cpp ├── 24.cpp ├── ABSP1.cpp ├── DOL.cpp ├── ESYRCRTN.cpp ├── GIRLSNBS.cpp ├── MOHIB.cpp ├── PHT.cpp ├── PRIME1.cpp ├── QUADAREA.cpp ├── SPCQ.cpp ├── a.out ├── acpc11b.cpp ├── army.cpp ├── codchess.cpp ├── crds.cpp ├── ec_conb.cpp ├── fashion.cpp ├── fctrl.cpp ├── fctrl2(c++17).cpp ├── fctrl2(using int array).cpp ├── ieeeeebgam.cpp ├── infix2postfix.cpp ├── printXor.cpp ├── smpseq8.cpp └── smpwow.cpp └── system-design └── README.md /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: omonimus1 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | ** Folder ** 14 | 15 | ** Solution interested ** 16 | 17 | 18 | **To Reproduce** 19 | [Indicate any testcase used to spot the bug] 20 | 21 | **Expected result** 22 | A clear and concise description of what you expected to happen. 23 | 24 | **Screenshots** 25 | If applicable, add screenshots to help explain your problem. 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | .vs/ 3 | .vscode/ 4 | a.out -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution guide 2 | 3 | 1. Fork the repository 4 | 2. Add a new solution just if your solution does not exists in the name branch of this repository or if your solution is faster then a current present solution 5 | 3. Leave a star to the project to let other users know about this competitive programming guide 6 | 4. Create a pull request 7 | -------------------------------------------------------------------------------- /HackerRank/README.md: -------------------------------------------------------------------------------- 1 | ## Visit my HackerRank solution 2 | 3 | Hi, My HackerRank Solutions has been moved in a dedicated repository, as the list of solutions is keep growing. 4 | [Follow this link to view HackerRank Solutions](https://github.com/omonimus1/HackerRank-Solutions) 5 | -------------------------------------------------------------------------------- /Lectures/CS97SISlides/01-introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/01-introduction.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/02-mathematics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/02-mathematics.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/03-data-structures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/03-data-structures.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/04-dynamic-programming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/04-dynamic-programming.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/05-combinatorial-games.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/05-combinatorial-games.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/06-basic-graph-algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/06-basic-graph-algorithms.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/07-shortest-path-algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/07-shortest-path-algorithms.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/08-network-flow-problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/08-network-flow-problems.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/09-computational-geometry.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/09-computational-geometry.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/10-string-algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/10-string-algorithms.pdf -------------------------------------------------------------------------------- /Lectures/CS97SISlides/suffix-array.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Lectures/CS97SISlides/suffix-array.pdf -------------------------------------------------------------------------------- /Lectures/data-structures/Lecture15.md: -------------------------------------------------------------------------------- 1 | ## Counting and Probability 2 | 3 | Counting theory tries to answer the question "How many?" without enumaerating all the choices. 4 | 5 | An example could be 6 | * How many differnt n-bit number sare there? 7 | * How many anagrams can we create from this word? 8 | 9 | * **Permutations**: **ordered**(main different between permutation and combination), sequence of all the elements of a set S whcih each element appearing exactly one. 10 | 11 | Ex: S = {a,b,c} 12 | Permutations: 13 | {abc, acb, bac, cab, cba} 14 | 15 | Having N the number of elements of a set, the number of it's permutations are going to tbe N!. 16 | 17 | * **K-permutation**: permutation of K elements that are part of a set S. 18 | THe number of permutations will be: 19 | ``` 20 | N! / ( N-K )! 21 | ``` 22 | 23 | * **k-combinations:**: combination of n elements being part of the set S. 24 | Ex: 25 | S = {a,b,c,d} 26 | N = 2 27 | Combinations: {ab,ac,ad,bc,bd,cd} 28 | 29 | Number of combinations of N elements: 30 | ``` 31 | N! / K! * (N - K)! 32 | ``` -------------------------------------------------------------------------------- /Leetcode/README.md: -------------------------------------------------------------------------------- 1 | ### Index of core solutions for interview preparation 2 | 3 | 4 | Note: Not all the solutions reported in this index are the coding challenges solved on leetcode. I decided to create this index once I switched to interview preparation. Open the leetcode folder to see a wider set of solutions. 5 | 6 | |Exercise|Solution| 7 | |-------|:------:| 8 | |Contains Duplicate|[Python](contains_duplicate.py)| 9 | |Two sum|[Python](two_sum.py)| 10 | |Sort colors|[C++](sort_colors.cpp)| 11 | |maximum-count-of-positive-integer-and-negative-integer|[C++](sort_colors.cpp)| 12 | THread python|[Python](thread_python.py)| -------------------------------------------------------------------------------- /Leetcode/REPLACE-ELEMENT-WITH-greater-on-right-side.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/featured/card/fun-with-arrays/511/in-place-operations/3259/ 2 | class Solution { 3 | public: 4 | vector replaceElements(vector& arr) { 5 | int len = arr.size(); 6 | int biggest; 7 | for(int i =0; i < len-1; i++) 8 | { 9 | biggest = INT_MIN; 10 | for (int j= i+1; j < len; j++) 11 | { 12 | if(biggest < arr[j]) 13 | biggest = arr[j]; 14 | } 15 | arr[i] = biggest; 16 | } 17 | 18 | arr[len-1] = -1; 19 | return arr; 20 | } 21 | }; -------------------------------------------------------------------------------- /Leetcode/average-salary-excluding-min-and-max.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/submissions/ 2 | class Solution { 3 | public: 4 | double average(vector& salary) { 5 | int len = salary.size(); 6 | sort(salary.begin(), salary.end()); 7 | int sum = 0; 8 | for(int i =1; i < len-1; i++) 9 | sum += salary[i]; 10 | return (double)sum/(len-2); 11 | } 12 | }; -------------------------------------------------------------------------------- /Leetcode/average-salary.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/description/?envType=study-plan&id=programming-skills-i 2 | class Solution: 3 | def average(self, salary: List[int]) -> float: 4 | return ((sum(salary)- max(salary) - min(salary))/ (len(salary)-2) ) -------------------------------------------------------------------------------- /Leetcode/big-countries.sql: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/big-countries/submissions/ 2 | SELECT name, population, area 3 | FROM World 4 | WHERE population > 25000000 OR area > 3000000; -------------------------------------------------------------------------------- /Leetcode/binary-number-with-alternating-bits.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/binary-number-with-alternating-bits/submissions/ 2 | class Solution { 3 | public: 4 | bool hasAlternatingBits(int n) { 5 | vectors; 6 | while(n > 0) 7 | { 8 | s.push_back(n%2); 9 | n /=2; 10 | } 11 | for(int i =0; i < s.size()-1; i++) 12 | { 13 | if(s[i] == s[i+1]) 14 | return false; 15 | } 16 | return true; 17 | } 18 | }; -------------------------------------------------------------------------------- /Leetcode/binary-search.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/binary-search/submissions/ 2 | class Solution { 3 | public: 4 | int search(vector& nums, int target) { 5 | int left = 0; 6 | int right = nums.size()-1; 7 | 8 | while (left <= right) 9 | { 10 | int middle = left + (right-left)/2; 11 | if(nums[middle] == target) 12 | return middle; 13 | if(nums[middle] > target) 14 | right--; 15 | else 16 | left++; 17 | } 18 | return -1; 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/binary-tree-inorder.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/binary-tree-inorder-traversal/submissions/ 2 | class Solution { 3 | public: 4 | vectors; 5 | void inorder(TreeNode * root) 6 | { 7 | if(root == NULL) 8 | return; 9 | inorder(root->left); 10 | s.push_back(root->val); 11 | inorder(root->right); 12 | } 13 | 14 | vector inorderTraversal(TreeNode* root) { 15 | inorder(root); 16 | return s; // [1,2,3] 17 | } 18 | }; -------------------------------------------------------------------------------- /Leetcode/binary-tree-level-order-traversal-ii.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/binary-tree-level-order-traversal-ii/submissions/ 2 | class Solution { 3 | public: 4 | vector> levelOrderBottom(TreeNode* root) { 5 | vector> solution; 6 | 7 | if(root == NULL) 8 | return solution; 9 | 10 | queue q; 11 | q.push(root); 12 | 13 | TreeNode *node; 14 | 15 | while(!q.empty()) 16 | { 17 | vectorlevel; 18 | int size = q.size(); 19 | 20 | while(size--) 21 | { 22 | node = q.front(); 23 | q.pop(); 24 | level.push_back(node-> val); 25 | 26 | if(node->left != NULL) q.push(node->left); 27 | if(node->right != NULL) q.push(node->right); 28 | } 29 | 30 | solution.push_back(level); 31 | } 32 | 33 | reverse(solution.begin(), solution.end()); 34 | return solution; 35 | } 36 | }; -------------------------------------------------------------------------------- /Leetcode/binary-tree-preorder-traversal.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/binary-tree-preorder-traversal/submissions/ 2 | class Solution { 3 | public: 4 | vectors; 5 | void preoder(TreeNode *root) 6 | { 7 | if(root == NULL) 8 | return; 9 | s.push_back(root->val); 10 | preoder(root->left); 11 | preoder(root->right); 12 | } 13 | 14 | vector preorderTraversal(TreeNode* root) { 15 | preoder(root); 16 | return s; // [1,2,3] 17 | } 18 | }; -------------------------------------------------------------------------------- /Leetcode/check-if-a-number-is-majority-element-in-a-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array/submissions/ 2 | class Solution { 3 | public: 4 | bool isMajorityElement(vector& nums, int target) { 5 | int len = nums.size(); 6 | 7 | int counter = 0; 8 | for(int i =0; i < len; i++) 9 | { 10 | if(nums[i] == target) 11 | counter++; 12 | } 13 | if(counter > len/2) 14 | return true; 15 | return false; 16 | } 17 | }; -------------------------------------------------------------------------------- /Leetcode/check-if-n-and-its-double-exists.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/featured/card/fun-with-arrays/527/searching-for-items-in-an-array/3250/ 2 | class Solution { 3 | public: 4 | 5 | bool checkIfExist(vector& arr) { 6 | sort(arr.begin(), arr.end()); 7 | 8 | int len = arr.size(); 9 | if(len ==1) 10 | { 11 | return false; 12 | } 13 | if(len == 2) 14 | { 15 | if(arr[1] == arr[0]*2) 16 | return true; 17 | return false; 18 | } 19 | 20 | for(int i =0; i < len-1; i++) 21 | { 22 | for(int j=i+1; j < len; j++) 23 | { 24 | cout << arr[i] *2 <<" " << arr[j] <& nums) { 5 | unordered_mapmp; 6 | for(int i=0; i < nums.size(); i++) 7 | { 8 | mp[nums[i]]++; 9 | if(mp[nums[i]] > 1) 10 | return true; 11 | } 12 | return false; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /Leetcode/contains_duplicate.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given an integer array nums, return true if any value 3 | appears at least twice in the array, 4 | and return false if every element is distinct. 5 | """ 6 | class Solution: 7 | def containsDuplicate(self, nums: List[int]) -> bool: 8 | if len(nums) > len(set(nums)): 9 | return True 10 | return False -------------------------------------------------------------------------------- /Leetcode/count-negative-numbers-in-a-sorted-matrix.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/submissions/ 2 | class Solution { 3 | public: 4 | int countNegatives(vector>& grid) { 5 | int negative = 0; 6 | for(int i =0; i < grid.size(); i++) 7 | { 8 | for(int j=0; j < grid[i].size(); j++) 9 | { 10 | if(grid[i][j] < 0) 11 | negative+=1; 12 | } 13 | } 14 | return negative; 15 | } 16 | }; -------------------------------------------------------------------------------- /Leetcode/count-number-of-teams.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/count-number-of-teams/submissions/ 2 | class Solution { 3 | public: 4 | int numTeams(vector& rating) { 5 | int len = rating.size(); 6 | int solution = 0; 7 | for(int i = 0; i < len; i++) 8 | { 9 | for(int j=i+1; j < len; j++) 10 | { 11 | for(int k = j+1; k < len; k++) 12 | { 13 | if(rating[i] < rating[j] && rating[j] < rating[k]) 14 | solution+=1; 15 | if(rating[i] > rating[j] && rating[j] > rating[k]) 16 | solution+=1; 17 | } 18 | } 19 | 20 | } 21 | return solution; 22 | } 23 | }; -------------------------------------------------------------------------------- /Leetcode/countOdds.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/submissions/843465020/?envType=study-plan&id=programming-skills-i 2 | class Solution(object): 3 | def countOdds(self, low, high): 4 | """ 5 | :type low: int 6 | :type high: int 7 | :rtype: int 8 | """ 9 | if low % 2 == 0: 10 | return (high-low+1)//2 11 | return (high-low)//2 + 1 -------------------------------------------------------------------------------- /Leetcode/count_odds_in_number_interval.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/submissions/ 2 | class Solution { 3 | public: 4 | int countOdds(int low, int high) { 5 | int odds = 0; 6 | for(int i =low; i <=high; i++) 7 | { 8 | if(i%2 !=0){ 9 | odds++; 10 | } 11 | } 12 | return odds; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /Leetcode/counting-bits.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/counting-bits/submissions/ 2 | class Solution { 3 | public: 4 | 5 | int number_of_set_bit(int n) 6 | { 7 | int solution = 0; 8 | while(n > 0) 9 | { 10 | if (n%2) solution++; 11 | n/=2; 12 | } 13 | return solution; 14 | } 15 | 16 | vector countBits(int num) { 17 | vectors; 18 | for(int i =0; i <= num; i++) 19 | { 20 | s.push_back(number_of_set_bit(i)); 21 | } 22 | return s; 23 | } 24 | }; -------------------------------------------------------------------------------- /Leetcode/create-targe-array-in-the-given-order.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/create-target-array-in-the-given-order 2 | class Solution { 3 | public: 4 | vector createTargetArray(vector& nums, vector& index) { 5 | vectortarget; 6 | for(int i=0; i< index.size(); i++) 7 | { 8 | target.insert(target.begin() + index[i] , nums[i]); 9 | } 10 | return target; 11 | } 12 | }; -------------------------------------------------------------------------------- /Leetcode/defaining-an-ip.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/defanging-an-ip-address/submissions/ 2 | class Solution { 3 | public: 4 | string defangIPaddr(string address) { 5 | string final_ip = ""; 6 | for(int i =0; i< address.size(); i++) 7 | { 8 | if(address[i] == '.') 9 | // append() : append a string 10 | final_ip.append("[.]"); 11 | else 12 | // push_back() : append a char 13 | final_ip.push_back(address[i]); 14 | } 15 | return final_ip; 16 | } 17 | }; -------------------------------------------------------------------------------- /Leetcode/element-appearing-more-than-25-in-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/submissions/ 2 | class Solution { 3 | public: 4 | int findSpecialInteger(vector& arr) { 5 | if(arr.size() <= 2) 6 | return arr[0]; 7 | 8 | int frequency; 9 | int min = floor(arr.size()/4); 10 | 11 | 12 | for(int i =0; i < arr.size()-1 ; i++) 13 | { 14 | frequency = 0; 15 | while(arr[i] == arr[i+1]) 16 | { 17 | frequency++; 18 | if(frequency >= min) 19 | return arr[i]; 20 | i+=1; 21 | } 22 | } 23 | return -1; 24 | } 25 | }; -------------------------------------------------------------------------------- /Leetcode/final-prices-with-a-special-discount-in-a-shop.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/submissions/ 2 | class Solution { 3 | public: 4 | vector finalPrices(vector& prices) { 5 | int len = prices.size(); 6 | bool flag; 7 | for(int i =0; i < len-1; i++) 8 | { 9 | flag = false; 10 | for(int j =i+1; j < len; j++) 11 | { 12 | 13 | if(prices[j] <= prices[i]) 14 | { 15 | prices[i] -= prices[j]; 16 | flag =true; 17 | break; 18 | } 19 | if(flag) 20 | break; 21 | } 22 | } 23 | return prices; 24 | } 25 | }; -------------------------------------------------------------------------------- /Leetcode/find-all-duplicates-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/find-all-duplicates-in-an-array/submissions/ 2 | class Solution { 3 | public: 4 | vector findDuplicates(vector& nums) { 5 | int len = nums.size(); 6 | vectorsolution; 7 | sort(nums.begin(), nums.end()); 8 | for(int i =0; i < len-1; i++) 9 | { 10 | if(nums[i] == nums[i+1]) 11 | solution.push_back(nums[i]); 12 | } 13 | return solution; 14 | } 15 | }; -------------------------------------------------------------------------------- /Leetcode/find-duplicate.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/find-the-duplicate-number/submissions/ 2 | class Solution { 3 | public: 4 | int findDuplicate(vector& nums) { 5 | sort(nums.begin(), nums.end()); 6 | 7 | for(int i=0; i < nums.size()-1; i++) 8 | { 9 | if(nums[i] == nums[i+1]) 10 | return nums[i]; 11 | } 12 | return -1; 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/find-numbers-with-even-digits.cpp: -------------------------------------------------------------------------------- 1 | 2 | //https://leetcode.com/explore/featured/card/fun-with-arrays/521/introduction/3237/ 3 | class Solution { 4 | public: 5 | int findNumbers(vector& nums) { 6 | int single_number; 7 | 8 | unsigned int counter = 0, number_of_digits; 9 | for(int i =0; i< nums.size(); i++) 10 | { 11 | number_of_digits = 0; 12 | single_number = nums[i]; 13 | while(single_number > 0) 14 | { 15 | number_of_digits++; 16 | single_number /= 10; 17 | } 18 | if(number_of_digits % 2== 0) 19 | counter++; 20 | } 21 | return counter; 22 | } 23 | }; -------------------------------------------------------------------------------- /Leetcode/find-peak-element-facebook.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/facebook/54/sorting-and-searching-3/3032/ 2 | class Solution { 3 | public: 4 | int findPeakElement(vector& nums) { 5 | int len = nums.size(); 6 | if(len == 1 ) 7 | return 0; 8 | 9 | for(int i =0; i < len; i++) 10 | { 11 | if(i==0) 12 | { 13 | if(nums[0] > nums[1]) 14 | return 0; 15 | continue; 16 | } 17 | if(i == len-1) 18 | { 19 | if(nums[len-2] > nums[len-1]) 20 | return len-2; 21 | else if(nums[len-1] > nums[len-2]) 22 | return len-1; 23 | return -1; 24 | } 25 | if(nums[i] > nums[i-1] && nums[i] > nums[i+1]) 26 | return i; 27 | } 28 | return -1; 29 | } 30 | }; -------------------------------------------------------------------------------- /Leetcode/find-peak-element.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/find-peak-element/submissions/ 2 | class Solution { 3 | public: 4 | int findPeakElement(vector& nums) { 5 | int len = nums.size(); 6 | if(len == 1) 7 | return 0; 8 | 9 | if(len == 2) 10 | { 11 | if(nums[0] > nums[1]) 12 | return 0; 13 | if(nums[0] < nums[1]) 14 | return 1; 15 | else 16 | return -1; 17 | } 18 | if(nums[0] > nums[1]) 19 | return 0; 20 | for(int i =1; i < len-1; i++) 21 | { 22 | if(nums[i] > nums[i-1] && nums[i] > nums[i+1]) 23 | return i; 24 | } 25 | if(nums[len-1] > nums[len-2]) 26 | return len-1; 27 | return -1; 28 | } 29 | }; -------------------------------------------------------------------------------- /Leetcode/find-the-difference.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/find-the-difference/submissions/ 2 | class Solution { 3 | public: 4 | char findTheDifference(string s, string t) { 5 | int len_s = s.size(); 6 | if (len_s == 0) 7 | return t[0]; 8 | 9 | unordered_mapmap_s; 10 | unordered_mapmap_t; 11 | for(int i =0; i < s.size(); i++) 12 | map_s[s[i]]++; 13 | 14 | for(int i =0; i < t.size(); i++) 15 | map_t[t[i]]++; 16 | 17 | for(auto x : map_t) 18 | { 19 | if(!map_s.count(x.first)) 20 | return x.first; 21 | if(map_s[x.first] != map_t[x.first]) 22 | return x.first; 23 | } 24 | return t[0]; 25 | } 26 | }; -------------------------------------------------------------------------------- /Leetcode/find-the-duplicate-number.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/top-interview-questions-hard/116/array-and-strings/834/ 2 | /* 3 | This can be solved in O(N^2 time), or in O(N) time using an unordered_map, or in O(N), 4 | if the array would be sorted; 5 | */ 6 | 7 | class Solution { 8 | public: 9 | int findDuplicate(vector& nums) { 10 | int len = nums.size(); 11 | for(int i =0; i< len-1; i++) 12 | { 13 | for(int j= i+1; j< len; j++) 14 | { 15 | if(nums[i] == nums[j]) 16 | return nums[i]; 17 | } 18 | } 19 | return -1; 20 | } 21 | 22 | }; -------------------------------------------------------------------------------- /Leetcode/find_pivot_index.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/find-pivot-index/ 2 | class Solution { 3 | public: 4 | int pivotIndex(vector& nums) { 5 | int entire_sum = 0; 6 | 7 | int len = nums.size(); 8 | if (len <=1) 9 | return 0; 10 | 11 | for(int i=0; i< len; i++) 12 | entire_sum += nums[i]; 13 | int sum_to_the_right = entire_sum; 14 | int sum_to_left = 0; 15 | 16 | 17 | for(int i=0; i < len; i++) 18 | { 19 | // decrease_right_sum 20 | sum_to_the_right-= nums[i]; 21 | if(sum_to_the_right == sum_to_left) 22 | return i; 23 | sum_to_left+= nums[i]; 24 | } 25 | return -1; 26 | } 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /Leetcode/first-last-index-of-an-element.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/submissions/ 2 | class Solution { 3 | public: 4 | vector searchRange(vector& nums, int target) { 5 | int first = -1, second =-1; 6 | int len = nums.size(); 7 | for(int i =0; i < len; i++) 8 | { 9 | if(nums[i] == target) 10 | { 11 | first = i; 12 | break; 13 | } 14 | } 15 | for(int i = len-1; i >=0; i--) 16 | { 17 | if(nums[i] == target) 18 | { 19 | second = i; 20 | break; 21 | } 22 | } 23 | vectorsolution; 24 | solution.push_back(first); 25 | solution.push_back(second); 26 | return solution; 27 | } 28 | }; 29 | 30 | // One solution providede by another Leetcode user: https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/discuss/861262/Easy-to-understand-iterative-solution-with-two-binary-searches -------------------------------------------------------------------------------- /Leetcode/first-unique-character.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/top-interview-questions-easy/127/strings/881/ 2 | class Solution { 3 | public: 4 | int firstUniqChar(string s) { 5 | unordered_mapmp; 6 | int len = s.size(); 7 | for(int i =0; i< len; i++) 8 | mp[s[i]]++; 9 | 10 | for(int i =0; i< len; i++) 11 | { 12 | if(mp[s[i]] == 1) 13 | return i; 14 | } 15 | return -1; 16 | } 17 | }; -------------------------------------------------------------------------------- /Leetcode/fizz-buzz.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/top-interview-questions-easy/102/math/743/ 2 | class Solution { 3 | public: 4 | vector fizzBuzz(int n) { 5 | vectorsolution; 6 | for(int i = 1; i<=n; i++) 7 | { 8 | if(i%3 ==0 && i%5 ==0) 9 | { 10 | solution.push_back("FizzBuzz"); 11 | continue; 12 | } 13 | if(i%3 == 0) 14 | solution.push_back("Fizz"); 15 | else if(i%5 == 0) 16 | solution.push_back("Buzz"); 17 | else 18 | solution.push_back(to_string(i)); 19 | 20 | } 21 | return solution; 22 | } 23 | }; -------------------------------------------------------------------------------- /Leetcode/fun-with-arays.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3245/ 2 | class Solution { 3 | public: 4 | void duplicateZeros(vector& arr) { 5 | int len = arr.size(); 6 | if(len == 1) 7 | { 8 | return; 9 | } 10 | if(len == 2) 11 | { 12 | if(arr[0] == 0) 13 | arr[1] = 0; 14 | return; 15 | } 16 | for(int i=0; i< len-1; i++) 17 | { 18 | if(arr[i] == 0) 19 | { 20 | // shift 21 | for(int j = len-1; j >= i+1; j--) 22 | arr[j] = arr[j-1]; 23 | // Set next to zero 24 | arr[i+1] = 0; 25 | // Increment i so that we do not count again the new 0; 26 | i+=1; 27 | } 28 | 29 | } 30 | } 31 | }; -------------------------------------------------------------------------------- /Leetcode/how-many-numbers-are-smaller-then-current-number.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/ 2 | class Solution { 3 | public: 4 | vector smallerNumbersThanCurrent(vector& nums) { 5 | // Create solution vector 6 | vectorsolution; 7 | int counter, current_number; 8 | for(int i=0; i< nums.size(); i++) 9 | { 10 | counter = 0; 11 | current_number = nums[i]; 12 | for(int a = 0; a < nums.size(); a++) 13 | { 14 | if(a == i) 15 | continue; 16 | if(nums[a] < current_number) 17 | counter++; 18 | } 19 | solution.push_back(counter); 20 | } 21 | return solution; 22 | } 23 | }; -------------------------------------------------------------------------------- /Leetcode/implement-queue-suing-stacks.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/implement-queue-using-stacks/submissions/ 2 | class MyQueue { 3 | public: 4 | /** Initialize your data structure here. */ 5 | queueq; 6 | int number; 7 | MyQueue() { 8 | } 9 | 10 | /** Push element x to the back of queue. */ 11 | void push(int x) { 12 | q.push(x); 13 | } 14 | 15 | /** Removes the element from in front of queue and returns that element. */ 16 | int pop() { 17 | number = q.front(); 18 | q.pop(); 19 | return number; 20 | } 21 | 22 | /** Get the front element. */ 23 | int peek() { 24 | return q.front(); 25 | } 26 | 27 | /** Returns whether the queue is empty. */ 28 | bool empty() { 29 | return q.empty(); 30 | } 31 | }; -------------------------------------------------------------------------------- /Leetcode/invalid-tweets.sql: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/invalid-tweets/submissions/ 2 | SELECT tweet_id 3 | FROM Tweets 4 | WHERE character_length(content)> 15; -------------------------------------------------------------------------------- /Leetcode/jewels-and-stones.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/jewels-and-stones/submissions/ 2 | class Solution { 3 | public: 4 | int numJewelsInStones(string J, string S) { 5 | unordered_mapmp; 6 | for (int i = 0; i < S.size(); i++) 7 | mp[S[i]]++; 8 | int solution = 0; 9 | for (int i = 0; i < J.size(); i++) 10 | solution += mp[J[i]]; 11 | 12 | return solution; 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/kids-with-the-greatest-number-of-candies.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/submissions/ 2 | 3 | class Solution { 4 | public: 5 | vector kidsWithCandies(vector& candies, int extraCandies) { 6 | vectorsolution; 7 | 8 | int biggest = -99999999; 9 | for(int i =0; i < candies.size(); i++) { if(candies[i] > biggest) biggest = candies[i]; } 10 | for(int i =0; i < candies.size(); i++) 11 | { 12 | if(candies[i]+extraCandies >= biggest) 13 | solution.push_back(true); 14 | else 15 | solution.push_back(false); 16 | } 17 | return solution; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Leetcode/kth-larghest-element0-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/amazon/79/sorting-and-searching/482/ 2 | class Solution { 3 | public: 4 | int findKthLargest(vector& nums, int k) { 5 | sort(nums.begin(), nums.end()); 6 | int len = nums.size(); 7 | return nums[len-k]; 8 | } 9 | }; -------------------------------------------------------------------------------- /Leetcode/larghest-unique-number.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/largest-unique-number/submissions 2 | class Solution { 3 | public: 4 | int largestUniqueNumber(vector& A) { 5 | int biggest = INT_MIN; 6 | int len = A.size(); 7 | unordered_mapmp; 8 | for(int i =0; i < len; i++) 9 | mp[A[i]]++; 10 | 11 | for(auto x: mp) 12 | { 13 | if(x.second == 1) 14 | { 15 | if(x.first > biggest) 16 | biggest = x.first; 17 | } 18 | } 19 | if(biggest == INT_MIN) 20 | return -1; 21 | else 22 | return biggest; 23 | } 24 | }; -------------------------------------------------------------------------------- /Leetcode/lca-of-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | // Find Lowest Common Ancestor in a BST 2 | // https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ 3 | 4 | class Solution { 5 | public: 6 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { 7 | if(p->val < root->val && q->val < root->val) 8 | return lowestCommonAncestor(root->left , p, q); 9 | else if(p->val > root->val && q->val > root->val) 10 | return lowestCommonAncestor(root->right, p,q); 11 | return root; 12 | 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/length-of-last-word.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/length-of-last-word/submissions/ 2 | class Solution { 3 | public: 4 | int lengthOfLastWord(string s) { 5 | 6 | stringstream str(s); 7 | string word; 8 | int ans = 0; 9 | 10 | while(str >> word){ 11 | ans = word.size(); 12 | } 13 | return ans; 14 | } 15 | }; -------------------------------------------------------------------------------- /Leetcode/linked-list-cycle.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/linked-list-cycle/submissions/ 2 | class Solution { 3 | public: 4 | bool hasCycle(ListNode *head) { 5 | if(head == NULL) 6 | return false; 7 | 8 | ListNode *slow = head; 9 | ListNode *fast = head; 10 | 11 | while(slow && fast && fast->next) 12 | { 13 | slow = slow->next; 14 | fast = fast->next->next; 15 | if(slow == fast) 16 | return true; 17 | } 18 | return false; 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/lucky_number_in_an_array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/find-lucky-integer-in-an-array/submissions/ 2 | class Solution { 3 | public: 4 | int findLucky(vector& arr) { 5 | int len = arr.size(); 6 | int frequency; 7 | int current_luky = INT_MIN; 8 | for(int i =0; i < len; i++) 9 | { 10 | frequency =0; 11 | for(int j = 0; j < len; j++) 12 | { 13 | if(arr[i] == arr[j]) 14 | frequency++; 15 | } 16 | if(frequency == arr[i]) 17 | { 18 | if(arr[i]> current_luky) 19 | current_luky = arr[i]; 20 | } 21 | } 22 | 23 | if(current_luky == INT_MIN) 24 | return -1; 25 | return current_luky; 26 | } 27 | }; -------------------------------------------------------------------------------- /Leetcode/majority-element.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/majority-element/submissions/ 2 | class Solution { 3 | public: 4 | int majorityElement(vector& nums) { 5 | int len = nums.size(); 6 | 7 | int frequency = len/2; 8 | unordered_mapmp; 9 | 10 | for(int i =0; i < len; i++) 11 | { 12 | mp[nums[i]]++; 13 | } 14 | 15 | for(auto x: mp) 16 | { 17 | if(x.second > frequency) 18 | return x.first; 19 | } 20 | return -1; 21 | } 22 | }; -------------------------------------------------------------------------------- /Leetcode/matrix-diagonal-sum.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/matrix-diagonal-sum/submissions/ 2 | class Solution { 3 | public: 4 | int diagonalSum(vector>& mat) { 5 | int SIZE = mat.size(); 6 | int sum_main = 0, sum_second = 0; 7 | // Get sum of the main diagonal 8 | for(int i =0; i< SIZE; i++) 9 | sum_main += mat[i][i]; 10 | 11 | // Get sum of the second diagonal; 12 | for (int i = 0; i < SIZE; i++){ 13 | if(i == SIZE-1-i) 14 | continue; 15 | else 16 | sum_second += mat[i][SIZE-i-1]; 17 | } 18 | return sum_main + sum_second; 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/max-consecutive-onse.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/max-consecutive-ones/submissions/ 2 | class Solution { 3 | public: 4 | int findMaxConsecutiveOnes(vector& nums) { 5 | if(nums.size() == 1) 6 | return nums[0]; 7 | int max = 0; 8 | int counter=0; 9 | 10 | 11 | for(int i =0; i < nums.size(); i++) 12 | { 13 | if(nums[i] == 1) 14 | { 15 | counter++; 16 | max = counter > max ? counter : max; 17 | } 18 | // if we have a 0 19 | else 20 | counter = 0; 21 | } 22 | return max; 23 | } 24 | }; -------------------------------------------------------------------------------- /Leetcode/max-depth-of-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/learn/card/data-structure-tree/134/traverse-a-tree/931/ 2 | class Solution { 3 | public: 4 | int maxDepth(TreeNode* root) { 5 | if(root == NULL) 6 | return 0; 7 | 8 | int left_max = maxDepth(root->left); 9 | int right_max = maxDepth(root->right); 10 | return max(left_max, right_max)+1; 11 | } 12 | }; -------------------------------------------------------------------------------- /Leetcode/maximum-69-number.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/maximum-69-number/submissions/ 2 | class Solution { 3 | public: 4 | int maximum69Number (int num) { 5 | string number = to_string(num); 6 | for(int i =0; i < number.size(); i++) 7 | { 8 | if(number[i] == '6') 9 | { 10 | number[i] = '9'; 11 | return stoi(number); 12 | } 13 | } 14 | return num; 15 | } 16 | }; -------------------------------------------------------------------------------- /Leetcode/maximum-product-of-two-elements-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/ 2 | class Solution { 3 | public: 4 | int maxProduct(vector& nums) { 5 | long int product = INT_MIN; 6 | int len = nums.size(); 7 | long int current_product; 8 | for(int i =0; i < len-1; i++) 9 | { 10 | for(int j=i+1; j < len; j++) 11 | { 12 | current_product = (nums[i]-1)*(nums[j]-1); 13 | if(current_product > product) 14 | product = current_product; 15 | } 16 | } 17 | return product; 18 | 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/merge-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3253/ 2 | class Solution { 3 | public: 4 | void merge(vector& nums1, int m, vector& nums2, int n) { 5 | int end = m+n; 6 | int current_index_array_1 = m; 7 | for(int i=0; i< n; i++) 8 | { 9 | nums1[current_index_array_1] = nums2[i]; 10 | current_index_array_1 +=1; 11 | } 12 | sort(nums1.begin(), nums1.end()); 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/middle-of-linked-list.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/middle-of-the-linked-list/submissions/ 2 | class Solution { 3 | public: 4 | int nodesCounter(ListNode* head) 5 | { 6 | if(head == NULL) 7 | return 0; 8 | int counter = 0; 9 | while(head!= NULL) 10 | { 11 | counter++; 12 | head = head->next; 13 | } 14 | return counter; 15 | } 16 | 17 | ListNode* middleNode(ListNode* head) { 18 | if(head->next == NULL) 19 | return head; 20 | ListNode* current = head; 21 | int number_of_nodes = nodesCounter(current); 22 | 23 | current = head; 24 | number_of_nodes = (number_of_nodes/2)+1; 25 | 26 | while(current != NULL && number_of_nodes>1) 27 | { 28 | number_of_nodes--; 29 | current = current->next; 30 | } 31 | return current; 32 | } 33 | }; -------------------------------------------------------------------------------- /Leetcode/missing-number.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/missing-number/submissions/ 2 | class Solution { 3 | public: 4 | int missingNumber(vector& nums) { 5 | int len = nums.size(); 6 | sort(nums.begin(), nums.end()); 7 | for(int i =0; i < len; i++) 8 | { 9 | if(nums[i] != i) 10 | return i; 11 | } 12 | return 1+nums[len-1]; 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/morris.cpp: -------------------------------------------------------------------------------- 1 | /* Tree Node 2 | struct Node { 3 | int data; 4 | Node* left; 5 | Node* right; 6 | };*/ 7 | #include 8 | using namespace std; 9 | class Solution { 10 | public: 11 | vector inOrder(Node* root) 12 | { 13 | Node*cur=root; 14 | vectorv; 15 | //code here 16 | while(cur){ 17 | if(!cur->left) {v.push_back(cur->data); cur=cur->right;} 18 | else{ 19 | Node*pred=cur->left; 20 | while(pred->right and pred->right!=cur) pred=pred->right; 21 | if(!pred->right){ 22 | pred->right=cur; 23 | cur=cur->left; 24 | } 25 | else{ 26 | pred->right=NULL; 27 | v.push_back(cur->data); 28 | cur=cur->right; 29 | } 30 | 31 | } 32 | } 33 | return v; 34 | } 35 | }; -------------------------------------------------------------------------------- /Leetcode/move-zeros.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/move-zeroes/submissions/ 2 | class Solution { 3 | public: 4 | void moveZeroes(vector& nums) { 5 | int len = nums.size(); 6 | // count number of zeros 7 | int zeros = 0; 8 | for(int i =0; i < len ;i++) 9 | { 10 | if(nums[i] == 0) 11 | zeros++; 12 | } 13 | // if there are no 0 or there are just zeros, return 14 | if(zeros == 0 || zeros == len ) 15 | return; 16 | int j=0; 17 | for(int i = 0; i< len; i++) 18 | { 19 | if(nums[i] != 0) 20 | { 21 | nums[j] = nums[i]; 22 | j++; 23 | } 24 | } 25 | // Now, insert all the zeros at the end; 26 | for(int i = len-zeros; i < len; i++) 27 | nums[i] = 0; 28 | } 29 | }; -------------------------------------------------------------------------------- /Leetcode/n-repeated-element-in-size-2n-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/n-repeated-element-in-size-2n-array/submissions/ 2 | class Solution { 3 | public: 4 | int repeatedNTimes(vector& A) { 5 | unordered_mapmp; 6 | int len = A.size(); 7 | int frequency = len /2; 8 | 9 | for(int i =0; i < len; i++) 10 | mp[A[i]]++; 11 | 12 | for(auto x: mp) 13 | { 14 | if(x.second == frequency) 15 | return x.first; 16 | } 17 | return -1; 18 | } 19 | }; -------------------------------------------------------------------------------- /Leetcode/number-of-1-bits.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/number-of-1-bits/submissions/ 2 | class Solution { 3 | public: 4 | int hammingWeight(uint32_t n) { 5 | int solution =0; 6 | while(n >0) 7 | { 8 | if(n % 2) solution++; 9 | n/=2; 10 | } 11 | return solution; 12 | } 13 | }; -------------------------------------------------------------------------------- /Leetcode/number-of-islands.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/amazon/78/trees-and-graphs/894/ 2 | class Solution { 3 | public: 4 | 5 | void callDFS(vector>& grid, int i, int j) 6 | { 7 | if(i <0 || i >= grid.size() || j >= grid[i].size() || grid[i][j] == '0') 8 | return; 9 | 10 | grid[i][j] = '0'; 11 | // Check up 12 | callDFS(grid, i+1, j); 13 | // CHECK DOWN 14 | callDFS(grid, i-1, j); 15 | // CHeck right 16 | callDFS(grid, i, j+1); 17 | // check left 18 | callDFS(grid, i, j-1); 19 | } 20 | 21 | int numIslands(vector>& grid) { 22 | int counter =0; 23 | for(int i =0 ; i< grid.size(); i++) 24 | { 25 | for(int j =0; j < grid[i].size(); j++) 26 | { 27 | if(grid[i][j] == '1') 28 | { 29 | counter += 1; 30 | callDFS(grid, i, j); 31 | } 32 | } 33 | } 34 | 35 | return counter; 36 | } 37 | }; -------------------------------------------------------------------------------- /Leetcode/number-of-students-doing-homework-at-a-given-time.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time/submissions/ 2 | 3 | class Solution { 4 | public: 5 | int busyStudent(vector& startTime, vector& endTime, int queryTime) { 6 | int counter=0; 7 | for(int i =0; i < startTime.size(); i++) 8 | { 9 | if(startTime[i] <= queryTime && endTime[i] >= queryTime) 10 | counter++; 11 | } 12 | return counter; 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/number_of_good_pairs.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/number-of-good-pairs/submissions/ 2 | class Solution { 3 | public: 4 | int numIdenticalPairs(vector& nums) { 5 | int sol = 0; 6 | int len = nums.size(); 7 | for(int i =0; i < len-1; i++) 8 | { 9 | for(int j=i+1; j < len; j++) 10 | { 11 | if(nums[i] == nums[j]) 12 | sol++; 13 | } 14 | } 15 | return sol; 16 | } 17 | }; -------------------------------------------------------------------------------- /Leetcode/palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPalindrome(int x) { 4 | string a = to_string(x); 5 | if(a.size() ==1) 6 | return true; 7 | if(a.size()==2) 8 | { 9 | if(a[0] == a[1]) 10 | return true; 11 | return false; 12 | } 13 | 14 | int end = a.size()-1; 15 | for(int i =0; i 0) 6 | { 7 | if(n == 1) 8 | return true; 9 | if(n % 3 !=0) 10 | return false; 11 | n /=3; 12 | } 13 | return false; 14 | } 15 | }; -------------------------------------------------------------------------------- /Leetcode/power-of-two.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/power-of-two/submissions/ 2 | class Solution { 3 | public: 4 | bool isPowerOfTwo(int n) { 5 | while(n > 0) 6 | { 7 | if (n == 1) 8 | return true; 9 | if (n % 2 != 0) 10 | return false; 11 | n /= 2; 12 | } 13 | return false; 14 | } 15 | }; -------------------------------------------------------------------------------- /Leetcode/range-sum-of-bst.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/range-sum-of-bst/submissions/ 2 | class Solution { 3 | public: 4 | 5 | vectorinorder_vector; 6 | 7 | void inorder(TreeNode *root) 8 | { 9 | if(root == NULL) 10 | return; 11 | inorder(root->left); 12 | inorder_vector.push_back(root->val); 13 | inorder(root->right); 14 | } 15 | 16 | int rangeSumBST(TreeNode* root, int L, int R) { 17 | inorder(root); 18 | int sum=0; 19 | for(int i =0; i < inorder_vector.size(); i++) 20 | { 21 | if(inorder_vector[i]>= L && inorder_vector[i] <= R) 22 | sum += inorder_vector[i]; 23 | } 24 | 25 | return sum; 26 | } 27 | }; -------------------------------------------------------------------------------- /Leetcode/recyclable-and-low-fat-products.sql: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/recyclable-and-low-fat-products/ 2 | SELECT product_id 3 | FROM Products 4 | WHERE low_fats = 'Y' AND recyclable = 'Y'; -------------------------------------------------------------------------------- /Leetcode/remove-duplicates-from-array.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/remove-duplicates-from-sorted-array/submissions/ 2 | /* 3 | A solution could be use an unordered_set, simply iterate the array and push any element in the set, 4 | of course, storing just the unique elements and then return the size of the set. 5 | 6 | Another method is to sort first the array (in this case sorted), and use the unique function provided by C++. 7 | 8 | */ 9 | class Solution { 10 | public: 11 | int removeDuplicates(vector& nums) { 12 | nums.erase(std::unique(nums.begin(), nums.end()), nums.end()); 13 | return nums.size(); 14 | } 15 | }; -------------------------------------------------------------------------------- /Leetcode/remove-duplicates-from-linked-list.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/remove-duplicates-from-sorted-list/submissions/ 2 | /** 3 | * Definition for singly-linked list. 4 | * struct ListNode { 5 | * int val; 6 | * ListNode *next; 7 | * ListNode() : val(0), next(nullptr) {} 8 | * ListNode(int x) : val(x), next(nullptr) {} 9 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 10 | * }; 11 | */ 12 | class Solution { 13 | public: 14 | ListNode* deleteDuplicates(ListNode* head) { 15 | ListNode *current = head; 16 | if(current == NULL || current->next == NULL) 17 | return current; 18 | 19 | while(current!= NULL) 20 | { 21 | while(current->next != NULL && current->val == current->next->val) 22 | { 23 | ListNode *next = current->next->next; 24 | delete(current->next); 25 | current->next = next; 26 | } 27 | current = current->next; 28 | } 29 | 30 | return head; 31 | } 32 | }; -------------------------------------------------------------------------------- /Leetcode/remove-vowels-from-a-string.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/remove-vowels-from-a-string/submissions/ 2 | class Solution { 3 | public: 4 | bool isVowel(char x) 5 | { 6 | if(x == 'a' || x == 'A') 7 | return true; 8 | else if( x == 'e' || x == 'E') 9 | return true; 10 | else if (x == 'i' || x == 'I') 11 | return true; 12 | else if( x == 'o' || x == 'O' ) 13 | return true; 14 | else if( x == 'u' || x == 'U') 15 | return true; 16 | return false; 17 | } 18 | string removeVowels(string S) { 19 | int len = S.size(); 20 | string solution =""; 21 | for(int i=0; i < len; i++) 22 | { 23 | if(!isVowel(S[i])) 24 | solution += S[i]; 25 | } 26 | return solution; 27 | } 28 | }; -------------------------------------------------------------------------------- /Leetcode/replace_element.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/ 2 | class Solution { 3 | public: 4 | vector replaceElements(vector& arr) { 5 | int max; 6 | for(int i=0; i< arr.size(); i++) 7 | { 8 | max = -1; 9 | for(int j=i+1; j< arr.size(); j++) 10 | { 11 | if(arr[j] >max) 12 | max = arr[j]; 13 | } 14 | arr[i] = max; 15 | } 16 | return arr; 17 | } 18 | }; -------------------------------------------------------------------------------- /Leetcode/reverse-integer.cpp: -------------------------------------------------------------------------------- 1 | // Given a integer, reverse it: 2 | /* 3 | Es: x = -123 res = -321 4 | Es: x = 450 res = 54 5 | */ 6 | class Solution { 7 | public: 8 | int reverse(int x) { 9 | long res = 0; 10 | while (x) { 11 | // Add digit to an integer 12 | res = (res * 10) + (x % 10); 13 | x /= 10; 14 | } 15 | return (res < INT_MIN || res > INT_MAX) ? 0 : (int) res; 16 | } 17 | }; -------------------------------------------------------------------------------- /Leetcode/reverse-linked-list.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/amazon/77/linked-list/2979/ 2 | /** 3 | * Definition for singly-linked list. 4 | * struct ListNode { 5 | * int val; 6 | * ListNode *next; 7 | * ListNode() : val(0), next(nullptr) {} 8 | * ListNode(int x) : val(x), next(nullptr) {} 9 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 10 | * }; 11 | */ 12 | class Solution { 13 | public: 14 | ListNode* reverseList(ListNode* head) { 15 | if(head == NULL) 16 | return head; 17 | if(head->next == NULL) 18 | return head; 19 | vectortemp; 20 | ListNode *current = head; 21 | while(current != NULL) 22 | { 23 | temp.push_back(current->val); 24 | current = current->next; 25 | } 26 | reverse(temp.begin(), temp.end()); 27 | current = head; 28 | int i=0; 29 | while(current!= NULL) 30 | { 31 | current->val = temp[i]; 32 | i+=1; 33 | current = current->next; 34 | } 35 | return head; 36 | } 37 | }; -------------------------------------------------------------------------------- /Leetcode/reverse-only-letters.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/reverse-only-letters/submissions/ 2 | class Solution { 3 | public: 4 | bool isLetter(char x) 5 | { 6 | if(x >= 'a' && x <= 'z') 7 | return true; 8 | else if(x >= 'A' && x <= 'Z') 9 | return true; 10 | else 11 | return false; 12 | } 13 | 14 | string reverseOnlyLetters(string S) { 15 | string letters = ""; 16 | int len = S.size(); 17 | for(int i=0; i< len; i++) 18 | { 19 | if(isLetter(S[i])) 20 | letters += S[i]; 21 | } 22 | 23 | reverse(letters.begin(), letters.end()); 24 | int a=0; 25 | for(int i=0; i< len; i++) 26 | { 27 | if(isLetter(S[i])) 28 | { 29 | S[i] = letters[a]; 30 | a+=1; 31 | } 32 | } 33 | return S; 34 | } 35 | }; -------------------------------------------------------------------------------- /Leetcode/reverse-string.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/reverse-string/submissions/ 2 | /* 3 | Reverse string without use extra spacel 4 | */ 5 | class Solution { 6 | public: 7 | void reverseString(vector& s) { 8 | /* Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory */ 9 | 10 | int list_size = s.size(); 11 | // If string is empty or it has just one char 12 | if(list_size== 0 || list_size ==1) 13 | return; 14 | int end = list_size -1; 15 | for(int i =0; i < list_size/2; i++) 16 | { 17 | swap(s[i], s[end]); 18 | end--; 19 | } 20 | 21 | } 22 | }; -------------------------------------------------------------------------------- /Leetcode/reverse-vowels-of-a-string.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/reverse-vowels-of-a-string/submissions/ 2 | class Solution { 3 | public: 4 | 5 | char vowel_list[10] = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' }; 6 | 7 | bool is_vowel(char letter) 8 | { 9 | for(int i =0; i < 10; i++) 10 | { 11 | if(letter == vowel_list[i]) 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | string reverseVowels(string s) { 18 | int len = s.size(); 19 | 20 | string v = ""; 21 | for(int i=0; i < len; i++) 22 | { 23 | if(is_vowel(s[i])) 24 | v.push_back(s[i]); 25 | } 26 | 27 | reverse(v.begin(), v.end()); 28 | int j =0; 29 | for(int i =0; i < len; i++) 30 | { 31 | if(is_vowel(s[i])) 32 | { 33 | s[i] = v[j]; 34 | j++; 35 | } 36 | 37 | } 38 | return s; 39 | } 40 | }; -------------------------------------------------------------------------------- /Leetcode/reverse-words-in-a-string-iii.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/reverse-words-in-a-string-iii/submissions/ 2 | class Solution { 3 | public: 4 | string reverseWords(string s) { 5 | if(s == "") 6 | return s; 7 | if(s == " ") 8 | return s; 9 | vectortemporary; 10 | int len = s.size(); 11 | string word; 12 | for(int i =0; i < len ; i++) 13 | { 14 | word = ""; 15 | while(i < len && s[i] != ' ') 16 | { 17 | word += s[i]; 18 | i+=1; 19 | } 20 | if(word != "" && word != " ") 21 | { 22 | reverse(word.begin(), word.end()); 23 | temporary.push_back(word); 24 | } 25 | 26 | } 27 | len = temporary.size(); 28 | string result = ""; 29 | for(int i =0; i temp; 11 | string word; 12 | for(int i =0; i < len; i++) 13 | { 14 | word = ""; 15 | while(i < len && s[i] != ' ') 16 | { 17 | word += s[i]; 18 | i+=1; 19 | } 20 | if(word != "" && word != " ") 21 | temp.push_back(word); 22 | } 23 | 24 | len = temp.size(); 25 | if(len == 0) 26 | return ""; 27 | word = ""; 28 | for(int i =len-1; i >= 1; i--) 29 | { 30 | word += temp[i]; 31 | word += " "; 32 | } 33 | word += temp[0]; 34 | return word; 35 | } 36 | }; -------------------------------------------------------------------------------- /Leetcode/reverse_string2.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/top-interview-questions-easy/127/strings/879/ 2 | class Solution { 3 | public: 4 | void reverseString(vector& s) { 5 | /* Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory */ 6 | reverse(s.begin(), s.end()); 7 | } 8 | }; -------------------------------------------------------------------------------- /Leetcode/richest-customer-wealth.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/richest-customer-wealth/submissions/ 2 | class Solution { 3 | public: 4 | int maximumWealth(vector>& accounts) { 5 | int current_highest = INT_MIN; 6 | int highest = INT_MIN; 7 | for (int i = 0; i < accounts.size(); i++) 8 | { 9 | highest = 0; 10 | for (int j = 0; j < accounts[i].size(); j++) 11 | { 12 | highest += accounts[i][j]; 13 | } 14 | if (highest > current_highest) 15 | current_highest = highest; 16 | } 17 | return current_highest; 18 | 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/running-sum-of-1d-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/running-sum-of-1d-array/submissions/ 2 | class Solution { 3 | public: 4 | vector runningSum(vector& nums) { 5 | vectorsolution; 6 | int size = nums.size(); 7 | int sum; 8 | for(int i =0; i < size; i++) 9 | { 10 | sum += nums[i]; 11 | solution.push_back(sum); 12 | } 13 | return solution; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Leetcode/search-2d-matrix.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/search-a-2d-matrix/submissions/ 2 | class Solution { 3 | public: 4 | bool searchMatrix(vector>& matrix, int target) { 5 | for(int i=0; i< matrix.size(); i++) 6 | { 7 | for(int j = 0; j < matrix[i].size(); j++) 8 | { 9 | if(matrix[i][j] == target) 10 | return true; 11 | } 12 | } 13 | return false; 14 | } 15 | }; -------------------------------------------------------------------------------- /Leetcode/search-in-a-rotated-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/interview/card/amazon/79/sorting-and-searching/2992/ 2 | class Solution { 3 | public: 4 | int search(vector& nums, int target) { 5 | int len = nums.size(); 6 | for(int i =0; i < len; i++) 7 | { 8 | if(nums[i] == target) 9 | return i; 10 | } 11 | return -1; 12 | } 13 | }; -------------------------------------------------------------------------------- /Leetcode/search-in-binary-search-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode* searchBST(TreeNode* root, int val) { 4 | if(root == NULL) 5 | return NULL; 6 | else 7 | { 8 | if(root->val == val) 9 | return root; 10 | if(root->val > val) 11 | return searchBST(root->left, val); 12 | if(root->val < val) 13 | return searchBST(root->right, val); 14 | } 15 | return NULL; 16 | } 17 | }; -------------------------------------------------------------------------------- /Leetcode/search-in-rotated-sorted-array-ii.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/search-in-rotated-sorted-array-ii/submissions/ 2 | class Solution { 3 | public: 4 | bool search(vector& nums, int target) { 5 | for(int i =0; i < nums.size(); i++) 6 | { 7 | if(nums[i] == target) 8 | return true; 9 | } 10 | return false; 11 | } 12 | }; -------------------------------------------------------------------------------- /Leetcode/search-in-rotated-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/search-in-rotated-sorted-array/submissions/ 2 | class Solution { 3 | public: 4 | int search(vector& nums, int target) { 5 | for(int i =0; i < nums.size(); i++) 6 | { 7 | if(target == nums[i]) 8 | return i; 9 | } 10 | return -1; 11 | } 12 | }; -------------------------------------------------------------------------------- /Leetcode/search-insert-position.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/search-insert-position/submissions/ 2 | class Solution { 3 | public: 4 | int searchInsert(vector& nums, int target) { 5 | int len = nums.size(); 6 | // Last element is smaller 7 | if(nums[len-1] < target) 8 | return len; 9 | if(nums[0] > target) 10 | return 0; 11 | for(int i =0; i < nums.size(); i++) 12 | { 13 | if(nums[i] == target) 14 | return i; 15 | if(nums[i] > target) 16 | return i; 17 | } 18 | // Something went wront 19 | return -1; 20 | } 21 | }; -------------------------------------------------------------------------------- /Leetcode/self-dividing-numbers.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/self-dividing-numbers/submissions/ 2 | class Solution { 3 | public: 4 | vector selfDividingNumbers(int left, int right) { 5 | vectorsolution; 6 | bool is_self_divising; 7 | int single_digit, number; 8 | for(int i =left; i<= right; i++) 9 | { 10 | number = i; 11 | is_self_divising = true; 12 | while(number > 0) 13 | { 14 | single_digit = number % 10; 15 | number /=10; 16 | if(single_digit == 0 ||i % single_digit != 0 ) 17 | { 18 | is_self_divising = false; 19 | break; 20 | } 21 | } 22 | if(is_self_divising) 23 | solution.push_back(i); 24 | 25 | } 26 | 27 | return solution; 28 | } 29 | }; -------------------------------------------------------------------------------- /Leetcode/shaffle_the_array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/shuffle-the-array/ 2 | /* 3 | Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn]. 4 | 5 | Return the array in the form [x1,y1,x2,y2,...,xn,yn]. 6 | */ 7 | class Solution { 8 | public: 9 | vector shuffle(vector& nums, int n) { 10 | if(n <= 1) 11 | return nums; 12 | vector solution; 13 | 14 | for(int i=0;i < n; i++) 15 | { 16 | solution.push_back(nums[i]); 17 | solution.push_back(nums[i+n]); 18 | } 19 | return solution; 20 | } 21 | }; -------------------------------------------------------------------------------- /Leetcode/singleNumber.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | // Do XOR of all elements and return 5 | int res = nums[0]; 6 | for (int i = 1; i < nums.size(); i++) 7 | res = res ^ nums[i]; 8 | 9 | return res; 10 | } 11 | }; -------------------------------------------------------------------------------- /Leetcode/single_number_III.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/single-number-iii/ 2 | class Solution { 3 | public: 4 | vector singleNumber(vector& nums) { 5 | unordered_mapmp; 6 | int len = nums.size(); 7 | for(int i =0; i < len; i++) 8 | mp[nums[i]]++; 9 | 10 | vectorsolution; 11 | for(auto x : mp) 12 | { 13 | if(x.second == 1) 14 | solution.push_back(x.first); 15 | } 16 | return solution; 17 | } 18 | }; -------------------------------------------------------------------------------- /Leetcode/sort-an-array.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/sort-an-array/submissions/ 2 | class Solution { 3 | public: 4 | int partition(vector &nums, int start, int end) 5 | { 6 | 7 | int pivot = nums[end]; 8 | for(int i =start; i &nums, int start, int end) 21 | { 22 | if(start < end) 23 | { 24 | int pivot = partition(nums, start, end); 25 | quickSort(nums, start, pivot-1); 26 | quickSort(nums, pivot+1, end); 27 | } 28 | } 29 | 30 | vector sortArray(vector& nums) { 31 | 32 | int list_size = nums.size(); 33 | if (list_size <=1) return nums; 34 | 35 | 36 | quickSort(nums, 0, list_size-1); 37 | 38 | return nums; 39 | } 40 | 41 | }; -------------------------------------------------------------------------------- /Leetcode/sort-array-by-parity-ii.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/sort-array-by-parity-ii/ 2 | 3 | class Solution { 4 | public: 5 | vector sortArrayByParityII(vector& A) { 6 | int i; 7 | int len = A.size(); 8 | vectoreven; 9 | vectorodd; 10 | vectorsolution; 11 | for(i=0; i < len; i++) 12 | { 13 | if(A[i] % 2 ==0) 14 | even.push_back(A[i]); 15 | else 16 | odd.push_back(A[i]); 17 | } 18 | int a=0, b=0; 19 | for(int i =0; i < len; i++) 20 | { 21 | if(i % 2 == 0) 22 | { 23 | solution.push_back(even[a]); 24 | a+=1; 25 | } 26 | else 27 | { 28 | solution.push_back(odd[b]); 29 | b+=1; 30 | } 31 | } 32 | return solution; 33 | } 34 | }; -------------------------------------------------------------------------------- /Leetcode/sort-array-by-parity.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/explore/featured/card/fun-with-arrays/511/in-place-operations/3260/ 2 | class Solution { 3 | public: 4 | vector sortArrayByParity(vector& A) { 5 | int len = A.size(); 6 | int i; 7 | vectorsolution; 8 | for(i=0; i < len; i++) 9 | { 10 | if(A[i] %2 ==0) 11 | solution.push_back(A[i]); 12 | } 13 | for(i=0; i < len; i++) 14 | { 15 | if(A[i] % 2 !=0) 16 | solution.push_back(A[i]); 17 | } 18 | return solution; 19 | 20 | } 21 | }; -------------------------------------------------------------------------------- /Leetcode/squares-of-a-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/squares-of-a-sorted-array/submissions/ 2 | class Solution { 3 | public: 4 | vector sortedSquares(vector& A) { 5 | for(int i =0; i < A.size(); i++) 6 | { 7 | A[i] = pow(A[i], 2); 8 | } 9 | 10 | sort(A.begin(), A.end()); 11 | return A; 12 | } 13 | }; -------------------------------------------------------------------------------- /Leetcode/subtract-the-product-and-sum-of-digits-of-an-integer.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ 2 | class Solution { 3 | public: 4 | int subtractProductAndSum(int n) { 5 | if (n==0) 6 | return 0; 7 | int sum = 0; 8 | int product = 1; 9 | int single_digit; 10 | while(n > 0) 11 | { 12 | single_digit = n % 10; 13 | n /= 10; 14 | sum += single_digit; 15 | product *= single_digit; 16 | } 17 | return product - sum; 18 | } 19 | }; -------------------------------------------------------------------------------- /Leetcode/sum-of-digits-in-the-minimum-number.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/submissions/ 2 | class Solution { 3 | public: 4 | int sumOfDigits(vector& A) { 5 | int smallest = INT_MAX; 6 | int len = A.size(); 7 | 8 | 9 | for(int i =0; i< len; i++) 10 | { 11 | if(A[i] < smallest) 12 | smallest = A[i]; 13 | } 14 | 15 | int sum_digits = 0; 16 | while(smallest > 0) 17 | { 18 | sum_digits += smallest % 10; 19 | smallest /= 10; 20 | } 21 | if(sum_digits % 2 == 0) 22 | return 1; 23 | else 24 | return 0; 25 | } 26 | }; -------------------------------------------------------------------------------- /Leetcode/swap-nodes-in-pairs.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/swap-nodes-in-pairs/submissions/ 2 | /** 3 | * Definition for singly-linked list. 4 | * struct ListNode { 5 | * int val; 6 | * ListNode *next; 7 | * ListNode() : val(0), next(nullptr) {} 8 | * ListNode(int x) : val(x), next(nullptr) {} 9 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 10 | * }; 11 | */ 12 | class Solution { 13 | public: 14 | ListNode* swapPairs(ListNode* head) { 15 | if(head == NULL || head->next == NULL) 16 | return head; 17 | 18 | ListNode *current = head; 19 | while(current != NULL && current->next != NULL ) 20 | { 21 | swap(current->val, current->next->val); 22 | current = current->next->next; 23 | } 24 | return head; 25 | } 26 | }; -------------------------------------------------------------------------------- /Leetcode/three-consecutive-odds.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/three-consecutive-odds/submissions/ 2 | class Solution { 3 | public: 4 | bool threeConsecutiveOdds(vector& arr) { 5 | int len = arr.size(); 6 | if(len < 3) 7 | return false; 8 | if(len == 3) 9 | { 10 | if(arr[0] %2 !=0 && arr[1]%2 !=0) 11 | { 12 | if(arr[2] %2 !=0) 13 | return true; 14 | } 15 | return false; 16 | } 17 | for(int i =0; i <= len-3; i++) 18 | { 19 | if(arr[i] %2 !=0 && arr[i+1]%2 !=0) 20 | { 21 | if(arr[i+2] %2 !=0) 22 | return true; 23 | } 24 | } 25 | return false; 26 | } 27 | }; -------------------------------------------------------------------------------- /Leetcode/to-lower-case.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/to-lower-case/submissions/ 2 | class Solution { 3 | public: 4 | string toLowerCase(string str) { 5 | for(int i =0; i < str.size(); i++) 6 | { 7 | if(isupper(str[i])) 8 | str[i] = tolower(str[i]); 9 | } 10 | return str; 11 | } 12 | }; -------------------------------------------------------------------------------- /Leetcode/two-sum.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/two-sum/submissions/ 2 | class Solution { 3 | public: 4 | vector twoSum(vector& nums, int target) { 5 | vectors; 6 | for(int i =0; i < nums.size()-1; i++) 7 | { 8 | for(int j = i+1; j < nums.size(); j++) 9 | { 10 | if(nums[i] + nums[j] == target) 11 | { 12 | s.push_back(i); 13 | s.push_back(j); 14 | return s; 15 | } 16 | } 17 | } 18 | return s; 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/two_sum.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given an array of integers nums and an integer target, 3 | return indices of the two numbers such that they 4 | add up to target. 5 | 6 | You may assume that each input would have exactly 7 | one solution, and you may not use the same element 8 | twice. 9 | """ 10 | class Solution: 11 | def twoSum(self, nums: List[int], target: int) -> List[int]: 12 | for i in range(len(nums)): 13 | for j in range(i + 1, len(nums)): 14 | if nums[j] == target - nums[i]: 15 | return [i, j] -------------------------------------------------------------------------------- /Leetcode/unique-number-of-occurrences.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/unique-number-of-occurrences/submissions/ 2 | class Solution { 3 | public: 4 | bool uniqueOccurrences(vector& arr) { 5 | map mp; 6 | int len = arr.size(); 7 | for(int i =0; i < len; i++) 8 | mp[arr[i]]++; 9 | 10 | unordered_sets; 11 | int size_map = mp.size(); 12 | for(auto x:mp) 13 | s.insert(x.second); 14 | 15 | if(s.size() == size_map) 16 | return true; 17 | return false; 18 | 19 | } 20 | }; -------------------------------------------------------------------------------- /Leetcode/valid-anagram.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/valid-anagram/submissions/ 2 | /* Having two strings, checkk if s2 is the anagram of s1 */ 3 | class Solution { 4 | public: 5 | bool isAnagram(string s, string t) { 6 | 7 | if(s.size() != t.size()) 8 | return false; 9 | 10 | sort(s.begin(), s.end()); 11 | 12 | sort(t.begin(), t.end()); 13 | 14 | if(s == t) 15 | return true; 16 | return false; 17 | } 18 | }; -------------------------------------------------------------------------------- /Reading/2008_Book_AlgorithmsAndDataStructures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/2008_Book_AlgorithmsAndDataStructures.pdf -------------------------------------------------------------------------------- /Reading/2009_Book_AConciseAndPracticalIntroducti.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/2009_Book_AConciseAndPracticalIntroducti.pdf -------------------------------------------------------------------------------- /Reading/2015_Book_DataStructuresAndAlgorithmsWit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/2015_Book_DataStructuresAndAlgorithmsWit.pdf -------------------------------------------------------------------------------- /Reading/2019_Book_JavaScriptDataStructuresAndAlg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/2019_Book_JavaScriptDataStructuresAndAlg.pdf -------------------------------------------------------------------------------- /Reading/5 Algorithm Analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/5 Algorithm Analysis.pdf -------------------------------------------------------------------------------- /Reading/Competitive Programming 3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/Competitive Programming 3.pdf -------------------------------------------------------------------------------- /Reading/CompetitiveProgrammerHandbook.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/CompetitiveProgrammerHandbook.pdf -------------------------------------------------------------------------------- /Reading/Cracking-the-Coding-Interview-6th-Edition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/Cracking-the-Coding-Interview-6th-Edition.pdf -------------------------------------------------------------------------------- /Reading/Introduction_to_algorithms-3rd Edition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/Introduction_to_algorithms-3rd Edition.pdf -------------------------------------------------------------------------------- /Reading/Stacks Queues Priority Queues.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/Stacks Queues Priority Queues.pdf -------------------------------------------------------------------------------- /Reading/cp1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/Reading/cp1.pdf -------------------------------------------------------------------------------- /UVA/11727CostCutting.cpp: -------------------------------------------------------------------------------- 1 | // Author: Davide Pollicino 2 | // Date: 04/01/2019 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int main () 12 | { 13 | vector myVector; 14 | int n , a , b, c ; 15 | cin >> n; 16 | 17 | for (int i = 1; i<=n; i++) 18 | { 19 | cin >> a >> b >> c; 20 | myVector.push_back(a); 21 | myVector.push_back(b); 22 | myVector.push_back(c); 23 | sort(myVector.begin() , myVector.end()); 24 | cout << "Case " << i << ": " << myVector[1] << endl; 25 | myVector.clear(); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /UVA/12289_OneTwoThree.cpp: -------------------------------------------------------------------------------- 1 | // Author: Davide Pollicino 2 | // Date: 04/01/2010 3 | // 12289 - One-Two-Three 4 | // To fixxxxx 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main () 11 | { 12 | int n; // Number of words in input 13 | cin >> n; 14 | if (n <=0 ) 15 | return 0; 16 | else 17 | { 18 | string word; 19 | for(int i= 0 ; i< n; i++) 20 | { 21 | cin >> word; 22 | if (word.length() == 5) 23 | cout << "3" << endl; 24 | else if (word.length() == 3) 25 | { 26 | if (word[0] == 't' || word[1] == 'w' || word[2] == 'o') 27 | cout << "2" << endl; 28 | else 29 | cout << "1" << endl; 30 | } 31 | } 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /UVA/12372PackForHoliday.cpp: -------------------------------------------------------------------------------- 1 | // Author: Davide Pollicino 2 | // Date: 04/02/1999 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main () 9 | { 10 | int n , l , w, h; 11 | cin >> n; 12 | for (int i =1 ; i<=n ; i++) 13 | { 14 | cin >> l >> w >> h; 15 | if (l > 20 || w > 20 || h > 20) 16 | cout << "Case " << i << ": bad"< 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, totatAumount=0 , valuetoAdd = 0; 10 | string word; 11 | cin >> n; 12 | for (int i=0; i < n; i++) 13 | { 14 | cin >> word; 15 | if( word == "report") 16 | cout <> valuetoAdd; 20 | totatAumount+= valuetoAdd; 21 | } 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /UVA/12577Hajj_e_Akbar.cpp: -------------------------------------------------------------------------------- 1 | // Author: Davide Pollicino 2 | // Date: 04/01/2020 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string word = " "; 11 | int counter = 1; 12 | while(word != "*") 13 | { 14 | cin >> word; 15 | if (word == "Hajj") 16 | cout << "Case " << counter <<": " <<"Hajj-e-Akbar"< 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | string line; 10 | while (getline(cin, line)) 11 | { 12 | cout << line << endl; 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /UVA/UVA11172.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/UVA/UVA11172.cpp -------------------------------------------------------------------------------- /UVA/UVa11942LumberjackSequencing.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/UVA/UVa11942LumberjackSequencing.cpp -------------------------------------------------------------------------------- /algorithm/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/algorithm/a.out -------------------------------------------------------------------------------- /algorithm/generate-sub-arrays/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/algorithm/generate-sub-arrays/a.out -------------------------------------------------------------------------------- /algorithm/generate-sub-arrays/iterative-subarray-generator.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/algorithm/generate-sub-arrays/iterative-subarray-generator.cpp -------------------------------------------------------------------------------- /algorithm/generate-sub-arrays/store-all-sbuarrays.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/algorithm/generate-sub-arrays/store-all-sbuarrays.cpp -------------------------------------------------------------------------------- /algorithm/kadane_s_algorithm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/algorithm/kadane_s_algorithm.cpp -------------------------------------------------------------------------------- /algorithm/kadanes_NEGATIVE_numbers.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/algorithm/kadanes_NEGATIVE_numbers.cpp -------------------------------------------------------------------------------- /books/Programming Interviews Exposed ( PDFDrive.com ).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/books/Programming Interviews Exposed ( PDFDrive.com ).pdf -------------------------------------------------------------------------------- /books/htaph_theory.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/books/htaph_theory.pdf -------------------------------------------------------------------------------- /codebyte/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codebyte/README.md -------------------------------------------------------------------------------- /codebyte/longest_word/longest_word.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codebyte/longest_word/longest_word.java -------------------------------------------------------------------------------- /codebyte/prime_factorial/prime_factorial.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codebyte/prime_factorial/prime_factorial.java -------------------------------------------------------------------------------- /codebyte/reverse/reverse.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codebyte/reverse/reverse.java -------------------------------------------------------------------------------- /codechef/ADASCOOL.c: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/ADASCOOL 2 | #include 3 | 4 | int main() 5 | { 6 | int t; 7 | scanf("%d", &t); 8 | for (int i = 0; i < t && t <= 5000; i++) 9 | { 10 | int n, m; 11 | scanf("%d%d", &n, &m); 12 | 13 | if ((n >= 2 && n <= 50) && (m>=2 && m <= 50)) 14 | { 15 | if ((n * m) % 2 == 0) 16 | { 17 | printf("YES\n"); 18 | } 19 | else 20 | { 21 | printf("NO\n"); 22 | } 23 | } 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codechef/ATM2.c: -------------------------------------------------------------------------------- 1 | //https://www.codechef.com/problems/ATM2 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int t; 8 | scanf("%d", &t); 9 | 10 | for (int j = 0; j < t; j++) 11 | { 12 | int total, n, withdraw; 13 | scanf(" %d", &n); 14 | char output[n]; 15 | scanf(" %d", &total); 16 | 17 | for (int i = 0; i < n; i++) 18 | { 19 | scanf(" %d", &withdraw); 20 | 21 | if (withdraw <= total) 22 | { 23 | output[i] = '1'; 24 | total = total - withdraw; 25 | } 26 | else 27 | { 28 | output[i] = '0'; 29 | } 30 | } 31 | output[n]='\0'; 32 | 33 | printf("%s\n", output); 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /codechef/AVG.c: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/AVG 2 | #include 3 | 4 | int main() 5 | { 6 | int t; 7 | scanf("%d", &t); 8 | for (int i = 0; i < t; i++) 9 | { 10 | int n, k, v; 11 | scanf("%d%d%d", &n, &k, &v); 12 | 13 | int array[n]; 14 | int sum = 0; 15 | for (int i = 0; i < n; i++) 16 | { 17 | scanf("%d", &array[i]); 18 | sum += array[i]; 19 | } 20 | int expression = (v * (n + k) - sum); 21 | int x; 22 | if (expression % k != 0) 23 | { 24 | printf("-1\n"); 25 | } 26 | else 27 | { 28 | 29 | x = expression / k; 30 | 31 | if (x <=0) 32 | { 33 | printf("-1\n"); 34 | } 35 | else 36 | { 37 | 38 | printf("%d\n", x); 39 | } 40 | } 41 | } 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /codechef/BALLBOX.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/BALLBOX 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | for (int x = 0; x < t; x++) 10 | { 11 | int ball; 12 | cin >> ball; 13 | int k; 14 | cin >> k; 15 | 16 | int result; 17 | 18 | result = (k * (k + 1)) / 2; 19 | 20 | if (ball >= result) 21 | { 22 | cout << "YES" << endl; 23 | } 24 | else 25 | { 26 | cout << "NO" << endl; 27 | } 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /codechef/BROKENPHONE.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/BROKENPHONE 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | for (int i = 0; i < t; i++) 9 | { 10 | int repair = 0, newPhone = 0; 11 | 12 | cin >> repair >> newPhone; 13 | 14 | if (repair < newPhone) 15 | { 16 | cout << "REPAIR" << endl; 17 | } 18 | else if (newPhone < repair) 19 | { 20 | cout << "NEW PHONE" << endl; 21 | } 22 | else 23 | { 24 | cout << "ANY" << endl; 25 | } 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /codechef/BROKPHON.c: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/BROKPHON 2 | #include 3 | /* 7 1 1 1 3 3 3 2 4 | */ 5 | // Got accepted in the first time. 6 | // No Explaination used. 7 | // By Mohd Azeem 8 | int main() 9 | { 10 | int t; 11 | scanf("%d", &t); 12 | for (int i = 0; i < t; i++) 13 | { 14 | int n; 15 | scanf("%d", &n); 16 | 17 | int array[n]; 18 | for (int i = 0; i < n; i++) 19 | { 20 | scanf("%d", &array[i]); 21 | } 22 | int count = 0; 23 | 24 | if (array[0] != array[1]) 25 | { 26 | count++; 27 | } 28 | 29 | for (int i = 1; i < n - 1; i++) 30 | { 31 | if (array[i] != array[i - 1] || array[i] != array[i + 1]) 32 | { 33 | count++; 34 | } 35 | } 36 | if (array[n - 1] != array[n - 2]) 37 | { 38 | count++; 39 | } 40 | 41 | printf("%d\n", count); 42 | } 43 | return 0; 44 | } -------------------------------------------------------------------------------- /codechef/CABS.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/CABS 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | for (int n = 0; n < t; n++) 10 | { 11 | int x, y; 12 | cin >> x >> y; 13 | 14 | if (x == y) 15 | { 16 | cout << "ANY" << endl; 17 | } 18 | else if (x < y) 19 | { 20 | cout << "FIRST" << endl; 21 | } 22 | else 23 | { 24 | cout << "SECOND" << endl; 25 | } 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /codechef/CHFNSWAP.cpp: -------------------------------------------------------------------------------- 1 | //https://www.codechef.com/SEPT20B/problems/CHFNSWAP 2 | 3 | #include 4 | using namespace std; 5 | typedef long long loi; 6 | 7 | loi nC2(loi n) 8 | { 9 | if((n&1)==0) 10 | { 11 | return (n >> 1)*(n-1); 12 | } 13 | else 14 | { 15 | return n*((n-1) >> 1); 16 | } 17 | } 18 | 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | 24 | loi testCases; 25 | cin >> testCases; 26 | 27 | while(testCases--) 28 | { 29 | loi N, sum, halfSum, m, pivotSum, niceSwaps=0; 30 | cin >> N; 31 | 32 | sum = (N*(N+1))/2; 33 | halfSum = sum/2; 34 | m = floor((sqrt(4*sum+1)-1)/2); 35 | 36 | pivotSum = 0.5*m*(m+1); 37 | 38 | if(sum & 1) 39 | { 40 | niceSwaps = 0; 41 | } 42 | else 43 | { 44 | niceSwaps = ((pivotSum == halfSum) ? (nC2(m) + nC2(N-m)) : 0) + N-m; 45 | } 46 | 47 | cout << niceSwaps << endl; 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /codechef/DOLL.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/DOLL 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | for (int n = 0; n < t; n++) 10 | { 11 | int count = 0; 12 | int numberOfPlayers; 13 | cin >> numberOfPlayers; 14 | 15 | int Height; 16 | cin >> Height; 17 | 18 | int array[numberOfPlayers]; 19 | 20 | for (int i = 0; i < numberOfPlayers; i++) 21 | { 22 | cin >> array[i]; 23 | } 24 | for (int i = 0; i < numberOfPlayers; i++) 25 | { 26 | if (array[i] > Height) 27 | { 28 | count++; 29 | } 30 | } 31 | cout << count << endl; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /codechef/FEVER.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/FEVER 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | for (int i = 0; i < t; i++) 10 | { 11 | int temp; 12 | cin >> temp; 13 | 14 | temp > 98 ? cout << "YES" << endl : cout << "NO" << endl; 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /codechef/LONGSEQ.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/LONGSEQ 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | 10 | for (int x = 0; x < t; x++) 11 | { 12 | string number; 13 | cin >> number; 14 | 15 | long long int zero_count = 0; 16 | long long int one_count = 0; 17 | long long int length = number.length(); 18 | 19 | for (long long int i = 0; i < length; i++) 20 | { 21 | if (number[i] == '0') 22 | { 23 | zero_count++; 24 | } 25 | else 26 | { 27 | one_count++; 28 | } 29 | } 30 | 31 | if (zero_count == 1 || one_count == 1) 32 | { 33 | cout << "Yes" << endl; 34 | } 35 | else 36 | { 37 | cout << "No" << endl; 38 | } 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /codechef/MATCHES.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/MATCHES 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | for (int n = 0; n < t; n++) 10 | { 11 | int array[10]={6,2,5,5,4,5,6,3,7,6}; 12 | 13 | // for (int i = 0; i < 10; i++) 14 | // { 15 | // cout<>x>>y; 20 | 21 | int sum =x+y; 22 | int sticks=0; 23 | 24 | while(sum>0) 25 | { 26 | int rem=sum%10; 27 | sticks+= array[rem]; 28 | sum=sum/10; 29 | } 30 | 31 | cout< 3 | using namespace std; 4 | 5 | int main() { 6 | int count=0; 7 | for (int i = 0; i < 4; i++) { 8 | int x ; 9 | cin>>x; 10 | if(x>=10) 11 | { 12 | count++; 13 | } 14 | } 15 | cout< 3 | 4 | int main() 5 | { 6 | int testcase; 7 | scanf("%d", &testcase); 8 | 9 | for (int i = 0; i < testcase && testcase <= 288; i++) 10 | { 11 | 12 | int a, b, a1, b1, a2, b2, ans = 0; 13 | 14 | scanf("%d%d%d%d%d%d", &a, &b, &a1, &b1, &a2, &b2); 15 | 16 | if ((1 <= a <= 4) && (1 <= b <= 4) && (1 <= a1 <= 4) && (1 <= b1 <= 4) && (1 <= a2 <= 4) && (1 <= b2 <= 4) && (a != b) && (a1 != b1) && (a2 != b2)) 17 | { 18 | if (((a == a1)&& (b == b1)) || ((a == b1) && (b == a1))) 19 | { 20 | ans = 1; 21 | } 22 | 23 | if (((a == a2)&& (b == b2)) || ((a == b2) && (b == a2))) 24 | { 25 | ans = 2; 26 | } 27 | } 28 | printf("%d\n", ans); 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /codechef/README.md: -------------------------------------------------------------------------------- 1 | ## CodeChef 2 | 3 | * **Notice:** There could be more solutions listed within the folder itself than solutions categorized in this list. 4 | Any help for keeping track of the index is appreciated. 5 | 6 | | Name | Solution | 7 | |----------|:----------------:| 8 | |ATM|[Python](atm.py)| 9 | |Black cells in a chessboard|[Python](blackcel.py)| 10 | |Total expenses|[Python](total_expenses.py)| 11 | |Gross Salary|[Python](gross_salary.py)| 12 | ||[Python](.py)| 13 | -------------------------------------------------------------------------------- /codechef/TLG.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/TLG 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int rounds; 8 | cin >> rounds; 9 | 10 | int P1[rounds] = {0}; 11 | int P2[rounds] = {0}; 12 | int lead = 0; 13 | int SumOne = 0; 14 | int SumTwo = 0; 15 | int winner; 16 | 17 | for (int i = 0; i < rounds; i++) 18 | { 19 | cin >> P1[i] >> P2[i]; 20 | SumOne += P1[i]; 21 | SumTwo += P2[i]; 22 | if (SumOne > SumTwo) 23 | { 24 | 25 | if (SumOne - SumTwo > lead) 26 | { 27 | lead = SumOne - SumTwo; 28 | winner = 1; 29 | } 30 | } 31 | else 32 | { 33 | if (SumTwo - SumOne > lead) 34 | { 35 | lead = SumTwo - SumOne; 36 | winner = 2; 37 | } 38 | } 39 | } 40 | 41 | cout << winner << " " << lead; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /codechef/VOLCONTROL.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/VOLCONTROL 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin >> t; 9 | for (int i = 0; i < t && t <= 100; i++) 10 | { 11 | int x=0, y=0; 12 | cin >> x >> y; 13 | if (x <= 100 && y <= 100) 14 | { 15 | 16 | cout << ((x > y) ? x - y : y - x) << endl; 17 | } 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /codechef/ZOOZ.c: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/ZOOZ 2 | #include 3 | 4 | int main() 5 | { 6 | int t; 7 | scanf("%d", &t); 8 | for (int j = 0; j < t; j++) 9 | { 10 | int n; 11 | scanf("%d", &n); 12 | char string[n]; 13 | 14 | string[0] = '1'; 15 | 16 | for (int i = 1; i < n - 1; i++) 17 | { 18 | string[i] = '0'; 19 | } 20 | string[n - 1] = '1'; 21 | 22 | string[n] = '\0'; 23 | 24 | printf("%s\n", string); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /codechef/arm15a.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codechef/arm15a.cpp -------------------------------------------------------------------------------- /codechef/atm.py: -------------------------------------------------------------------------------- 1 | # https://www.codechef.com/problems/HS08TEST 2 | a,b =input().split() 3 | to_widthdrawn = int(a) 4 | available = float(b) 5 | if (to_widthdrawn %5 ==0) and to_widthdrawn<= available-0.50: 6 | new_amount = available - to_widthdrawn - 0.50 7 | print(round(new_amount, 2)) 8 | else: 9 | print(available) -------------------------------------------------------------------------------- /codechef/blackcel.py: -------------------------------------------------------------------------------- 1 | # https://www.codechef.com/problems/BLACKCEL 2 | board = int(input()) 3 | black_cell_for_row = (board / 2) 4 | black_cell = black_cell_for_row * board 5 | print(int(black_cell)) -------------------------------------------------------------------------------- /codechef/buying-new-tables.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void solve_test() 6 | { 7 | int number_options, budjet; 8 | int width, heigth, price; 9 | int max_width = 0, max_heiht = 0; 10 | cin >> number_options >> budjet; 11 | while (number_options--) 12 | { 13 | cin >> width >> heigth >> price; 14 | if (price > budjet) 15 | continue; 16 | else 17 | { 18 | // The price is within the budjet 19 | if ((max_heiht * max_width) < (heigth * width)) 20 | { 21 | max_width = width; 22 | max_heiht = heigth; 23 | } 24 | } 25 | } 26 | 27 | if (max_width == 0 && max_heiht == 0) 28 | cout << "no tablet" << endl; 29 | else 30 | cout << max_heiht * max_width << endl; 31 | } 32 | 33 | int main() { 34 | int test_cases; 35 | cin >> test_cases; 36 | 37 | while (test_cases--) 38 | solve_test(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /codechef/carvans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int counter; 7 | int n; 8 | 9 | void solve_test() 10 | { 11 | scanf("%d", &n); 12 | if (n == 1) 13 | { 14 | printf("1\n"); 15 | return; 16 | } 17 | else 18 | { 19 | vectors; 20 | int speed; 21 | for (int i = 0; i < n; i++) 22 | { 23 | scanf("%d", &speed); 24 | s.push_back(speed); 25 | } 26 | 27 | counter = 0; 28 | for (int i = 0; i < n - 1; i++) 29 | { 30 | if (s[i] > s[i + 1]) 31 | counter++; 32 | } 33 | printf("%d\n", counter); 34 | } 35 | } 36 | 37 | int main() { 38 | ios_base::sync_with_stdio(false); 39 | cin.tie(NULL); 40 | 41 | int t; 42 | scanf("%d", &t); 43 | for (int i = 0; i < t; i++) 44 | solve_test(); 45 | 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /codechef/chef-and-snackdown.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codechef/chef-and-snackdown.cpp -------------------------------------------------------------------------------- /codechef/choprt.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codechef/choprt.cpp -------------------------------------------------------------------------------- /codechef/devu_and_friendship_testing.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codechef/devu_and_friendship_testing.cpp -------------------------------------------------------------------------------- /codechef/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n,i; 6 | cin>>t;{ 7 | while(t>0){ 8 | cin>>n; 9 | int fact=1; 10 | if(n>0){ 11 | for(i=1; i<=n; i++) 12 | { 13 | fact=fact*i; 14 | 15 | } 16 | t--;} 17 | else if (n==0){ 18 | fact=1;} 19 | cout< 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | unsigned int t, a, b; 9 | cin >> t; 10 | while (t--) 11 | { 12 | cin >> a >> b; 13 | cout << a % b << endl; 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /codechef/flow004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int get_first_digit(long int n) 5 | { 6 | while (n >= 10) 7 | n /= 10; 8 | return n; 9 | } 10 | 11 | int get_last_digit(long int n) 12 | { 13 | return n % 10; 14 | } 15 | 16 | 17 | int main() { 18 | unsigned int t; 19 | long int number; 20 | cin >> t; 21 | while (t--) { 22 | cin >> number; 23 | 24 | cout << get_first_digit(number) + get_last_digit(number) << endl; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /codechef/flow006.cpp: -------------------------------------------------------------------------------- 1 | //https://www.codechef.com/problems/FLOW006 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t, total; 8 | long long n = 12345; 9 | cin >> t; 10 | while (t--) 11 | { 12 | 13 | total = 0; 14 | cin >> n; 15 | while (n != 0) 16 | { 17 | total += n % 10; 18 | n = n / 10; 19 | } 20 | cout << total << endl; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codechef/flow008.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t, e; 6 | cin >> t; 7 | for (int i = 0; i < t; i++) 8 | { 9 | cin >> e; 10 | if (e < 10) 11 | cout << "What an obedient servant you are!" << endl; 12 | else 13 | cout << "-1" << endl; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /codechef/flow018.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void calculate_factorial() 5 | { 6 | unsigned int number; 7 | unsigned int factorial = 1; 8 | cin >> number; 9 | for (int i = 1; i <= number; i++) 10 | factorial = factorial * i; 11 | 12 | cout << factorial << endl; 13 | } 14 | 15 | 16 | int main() { 17 | unsigned int test_cases; 18 | cin >> test_cases; 19 | for (int i = 0; i < test_cases; i++) 20 | { 21 | calculate_factorial(); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /codechef/flow17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void print_second_biggest() 7 | { 8 | long long a; 9 | vector vett; 10 | for (int i = 0; i < 3; i++) 11 | { 12 | cin >> a; 13 | vett.push_back(a); 14 | } 15 | sort(vett.begin(), vett.end()); 16 | cout << vett[vett.size() - 2] << endl; 17 | } 18 | 19 | int main() 20 | { 21 | // number of test cases 22 | int t; 23 | // Read number of test cases 24 | cin >> t; 25 | for (int i = 0; i < t; i++) 26 | print_second_biggest(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /codechef/fsqrt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print_root(int n) 5 | { 6 | cout << rint(sqrt(n)) << endl; 7 | } 8 | 9 | int main() 10 | { 11 | // number of test cases 12 | int t, n; 13 | // Read number of test cases 14 | cin >> t; 15 | for (int i = 0; i < t; i++) 16 | { 17 | cin >> n; 18 | print_root(n); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /codechef/gross_salary.py: -------------------------------------------------------------------------------- 1 | # https://www.codechef.com/problems/FLOW011 2 | for i in range(int(input())): 3 | basic_salary = int(input()) 4 | if basic_salary < 1500: 5 | hra = (basic_salary*10)/100 6 | da = (basic_salary*90)/100 7 | print(basic_salary+hra+da) 8 | else: 9 | hra = 500 10 | da = (basic_salary*98)/100 11 | print(basic_salary+hra+da) -------------------------------------------------------------------------------- /codechef/how-many-digits-do-i-have.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/HOWMANY 2 | #include 3 | using namespace std; 4 | 5 | void get_number_of_digits() 6 | { 7 | int number; 8 | cin >> number; 9 | int number_digits = 0; 10 | while (number > 0) 11 | { 12 | number_digits++; 13 | number /= 10; 14 | } 15 | if (number_digits > 3) 16 | cout << "More than 3 digits" << endl; 17 | else 18 | cout << number_digits << endl; 19 | } 20 | 21 | int main() { 22 | 23 | get_number_of_digits(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /codechef/how_much_scolariship.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/ZCOSCH 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | unsigned long long rank; 8 | cin >> rank; 9 | if (rank > 100) 10 | { 11 | cout << 0 << endl; 12 | return 0; 13 | } 14 | else if (rank >= 1 && rank <= 50) 15 | cout << 100 << endl; 16 | else if (rank >= 51 && rank <= 100) 17 | cout << 50 << endl; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /codechef/increment_or_decrement.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/DECINC 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | if (n % 4 == 0) 10 | n += 1; 11 | else 12 | n -= 1; 13 | cout << n; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /codechef/intest.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/INTEST 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long int number_of_tokens, token, divider; 8 | int counter = 0; 9 | cin >> number_of_tokens >> divider; 10 | // Best case: There are no number to analize; 11 | if (number_of_tokens == 0) 12 | { 13 | cout << '0'; 14 | return 0; 15 | } 16 | 17 | for (int i = 0; i < number_of_tokens; i++) 18 | { 19 | cin >> token; 20 | if (token % divider == 0) 21 | counter++; 22 | } 23 | cout << counter; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /codechef/is_it_vowel_or_consonant.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/VOWELTB 2 | // https://www.codechef.com/problems/VOWELTB 3 | 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | char character; 10 | cin >> character; 11 | if (character == 'A' || character == 'E' || character == 'I' || character == 'O' || character == 'U') 12 | cout << "Vowel" << endl; 13 | else 14 | { 15 | cout << "Consonant" << endl; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /codechef/luckfour.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codechef/luckfour.cpp -------------------------------------------------------------------------------- /codechef/magic-element.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/ZOZ 2 | #include 3 | 4 | using namespace std; 5 | 6 | int solve_test() 7 | { 8 | /* 9 | 4 4 10 | 2 1 6 7 11 | 4 2 12 | 2 1 5 4 13 | */ 14 | 15 | int n, k; 16 | cin >> n >> k; 17 | int arr[n]; // = {2,1,6,7}; 18 | for (int i = 0; i < n; i++) cin >> arr[i]; 19 | 20 | 21 | int magic = 0; 22 | int sum; 23 | int incremented_value; 24 | for (int i = 0; i < n; i++) 25 | { 26 | incremented_value = arr[i] + k; 27 | sum = 0; 28 | for (int j = 0; j < n; j++) 29 | { 30 | if (i == j) 31 | continue; 32 | sum += arr[j]; 33 | } 34 | 35 | if (incremented_value > sum) 36 | magic++; 37 | 38 | } 39 | 40 | return magic; 41 | } 42 | 43 | 44 | int main() 45 | { 46 | int t = 1; 47 | cin >> t; 48 | while (t--) 49 | cout << solve_test() << endl; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /codechef/mutated-minions.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/CHN15A 2 | #include 3 | using namespace std; 4 | 5 | void solve_test() 6 | { 7 | int n, k, current; 8 | cin >> n >> k; 9 | int arr[n]; 10 | int i; 11 | for (i = 0; i < n; i++) cin >> arr[i]; 12 | int result = 0; 13 | for (i = 0; i < n; i++) 14 | { 15 | current = arr[i] + k; 16 | if (current % 7 == 0) 17 | result++; 18 | } 19 | cout << result << endl; 20 | } 21 | 22 | int main() { 23 | int t; 24 | cin >> t; 25 | while (t--) 26 | solve_test(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /codechef/pall01.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/PALL01 2 | #include 3 | using namespace std; 4 | 5 | bool is_palindrome() 6 | { 7 | string number; 8 | cin >> number; 9 | int delimiter = number.size() - 1; 10 | for (int i = 0; i < number.size() / 2; i++) 11 | { 12 | if (number[i] != number[delimiter]) 13 | return false; 14 | delimiter--; 15 | } 16 | return true; 17 | } 18 | 19 | int main() { 20 | int t; 21 | cin >> t; 22 | bool palindrome_check; 23 | for (int i = 0; i < t; i++) 24 | { 25 | palindrome_check = is_palindrome(); 26 | if (palindrome_check) 27 | cout << "wins" << endl; 28 | else 29 | cout << "losses" << endl; 30 | 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /codechef/pretty_number.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/NUM239 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool isPrettyNumber(int number) 7 | { 8 | // Get last digit of the number 9 | int single_digit = number % 10; 10 | if (single_digit == 2 || single_digit == 3 || single_digit == 9) 11 | return true; 12 | else 13 | return false; 14 | } 15 | 16 | int main() 17 | { 18 | int test_cases; 19 | int a, b, counter; 20 | cin >> test_cases; 21 | while (test_cases--) 22 | { 23 | counter = 0; 24 | cin >> a >> b; 25 | for (int i = a; i <= b; i++) 26 | { 27 | if (isPrettyNumber(i)) 28 | counter++; 29 | } 30 | cout << counter << endl; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /codechef/prim1.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/PRIME1 2 | #include 3 | using namespace std; 4 | 5 | bool isPrime(long long int n) 6 | { 7 | if(n <=1) 8 | return false; 9 | for(int i =2; i> a >> b; 21 | if(a <=1 || b<=1) 22 | return; 23 | for(int i =a+1 ; i> test_cases; 35 | while(test_cases--) 36 | { 37 | generate_primes(); 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /codechef/primality-test.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/PRB01 2 | #include 3 | using namespace std; 4 | 5 | bool isPrime(long long int n) 6 | { 7 | if(n <=1) 8 | return false; 9 | for(int i =2; i> test_cases; 21 | while(test_cases--) 22 | { 23 | cin >> number; 24 | if(isPrime(number)) 25 | { 26 | cout <<"yes"< 3 | 4 | using namespace std; 5 | 6 | 7 | 8 | int get_sum_digits(string word) 9 | { 10 | // Case 1 : string is empty 11 | if(word.size() == 0) 12 | return 0; 13 | // Case 2: string is NOT empty 14 | int sum = 0; 15 | for(int i=0; i < word.size(); i++) 16 | { 17 | cout << "sum is: "<> test_cases; 35 | string word; 36 | while(test_cases--) 37 | { 38 | cin >> word; 39 | cout << get_sum_digits(word)< 3 | #include 4 | using namespace std; 5 | 6 | void reverse_string() 7 | { 8 | string number; 9 | cin >> number; 10 | int start_point = number.size()-1; 11 | // If the last numebr is 0 12 | if(number[number.size()-1] =='0') 13 | { 14 | for(int i = number.size()-1; i>=0; i--) 15 | { 16 | if(number[i] != number[i-1]) 17 | { 18 | start_point = i-1; 19 | break; 20 | } 21 | 22 | } 23 | } 24 | 25 | for(int i=start_point; i>=0; i--) 26 | { 27 | cout<>t; 39 | for(int i =0; i 3 | using namespace std; 4 | 5 | int main() { 6 | int num; 7 | cin >> num; 8 | cout << num; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /codechef/sum_two_number.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/FLOW001 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | // Read the number of test cases. 8 | int t; 9 | cin >> t; 10 | int a, b; 11 | while (t--) { 12 | // Read the input a, b 13 | cin >> a >> b; 14 | 15 | // Compute the ans. 16 | int ans = a + b; 17 | cout << ans << endl; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /codechef/tanu-head-bob.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/HEADBOB 2 | #include 3 | using namespace std; 4 | 5 | 6 | string solve_test() 7 | { 8 | int NO,YES, I, n=4; 9 | NO = YES = I = 0; 10 | cin >> n; 11 | string signs; 12 | cin >> signs; 13 | for(int i =0; i < n; i++) 14 | { 15 | if(signs[i] == 'I') 16 | return "INDIAN"; 17 | else if(signs[i] == 'Y') 18 | return "NOT INDIAN"; 19 | } 20 | return "NOT SURE"; 21 | } 22 | 23 | 24 | int main() 25 | { 26 | int t; 27 | cin >> t; 28 | while(t--) 29 | cout << solve_test()< 3 | using namespace std; 4 | int main() 5 | { 6 | int n , number; 7 | cin >>n; 8 | 9 | vectorelements; 10 | for(int i=0; i> number; 13 | elements.push_back(number); 14 | } 15 | 16 | sort(elements.begin() , elements.end()); 17 | for(int i=0; i< elements.size();i++) 18 | { 19 | cout < solution(vector inputArray) { 11 | // get the size of the longest string 12 | int longest_size = 0; 13 | int size = inputArray.size(); 14 | 15 | for(int i =0; i< size; i++) 16 | { 17 | if (longest_size < inputArray[i].size()){ 18 | longest_size = inputArray[i].size(); 19 | } 20 | } 21 | 22 | vector solution; 23 | for(int i =0; i< size; i++) 24 | { 25 | if (longest_size == inputArray[i].size()){ 26 | solution.push_back(inputArray[i]); 27 | } 28 | } 29 | return solution; 30 | } 31 | -------------------------------------------------------------------------------- /codesignal/alternating-sum.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/alternating-sum.cpp -------------------------------------------------------------------------------- /codesignal/candies.cpp: -------------------------------------------------------------------------------- 1 | // https://app.codesignal.com/arcade/code-arcade/intro-gates/DdNKFA3XCX6XN7bNz 2 | /* 3 | n children have got m pieces of candy. They want to eat as much candy as they can, but each child must eat exactly the same amount of candy as any other child. Determine how many pieces of candy will be eaten by all the children together. Individual pieces of candy cannot be split. 4 | 5 | Example 6 | 7 | For n = 3 and m = 10, the output should be 8 | solution(n, m) = 9. 9 | */ 10 | int solution(int n, int m) { 11 | return ceil(m/n)*n; 12 | } 13 | -------------------------------------------------------------------------------- /codesignal/century-from-year.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/century-from-year.cpp -------------------------------------------------------------------------------- /codesignal/check-palindrome.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/check-palindrome.cpp -------------------------------------------------------------------------------- /codesignal/codewriting.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | https://app.codesignal.com/arcade/code-arcade/at-the-crossroads/m9wjpkCjgofg7gs8N/solutions 4 | You are playing an RPG game. Currently your experience points (XP) 5 | total is equal to experience. To reach the next level your XP should be at 6 | least at threshold. If you kill the monster in front of you, you will gain more 7 | experience points in the amount of the reward. 8 | 9 | Given values experience, threshold and reward, check if you reach the next level after 10 | killing the monster. 11 | */ 12 | 13 | bool solution(int experience, int threshold, int reward) { 14 | if (threshold-experience <= reward) 15 | return true; 16 | return false; 17 | } 18 | -------------------------------------------------------------------------------- /codesignal/contains_duplicates.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/contains_duplicates.cpp -------------------------------------------------------------------------------- /codesignal/first-duplicate.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/first-duplicate.cpp -------------------------------------------------------------------------------- /codesignal/first-non-repeating-char.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/first-non-repeating-char.cpp -------------------------------------------------------------------------------- /codesignal/is_linked_list_palindrome.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/is_linked_list_palindrome.cpp -------------------------------------------------------------------------------- /codesignal/larghest_number.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Given an integer n, return the largest number that contains exactly n digits. 3 | https://app.codesignal.com/arcade/code-arcade/intro-gates/SZB5XypsMokGusDhX/solutions 4 | */ 5 | int solution(int n) { 6 | string number = ""; 7 | for(int i=0; i< n; i++){ 8 | number += '9'; 9 | } 10 | return stoi(number); 11 | } 12 | -------------------------------------------------------------------------------- /codesignal/max_multiple: -------------------------------------------------------------------------------- 1 | /* 2 | https://app.codesignal.com/arcade/code-arcade/intro-gates/HEsmEacHr2s9wahjr/solutions 3 | Given a divisor and a bound, find the largest integer N such that: 4 | 5 | N is divisible by divisor. 6 | N is less than or equal to bound. 7 | N is greater than 0. 8 | */ 9 | int solution(int divisor, int bound) { 10 | for (int i = bound; i>=0; i--) 11 | { 12 | if(i % divisor ==0 || divisor %i ==0) 13 | return i; 14 | } 15 | return -1; 16 | } 17 | -------------------------------------------------------------------------------- /codesignal/missing_number.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/missing_number.cpp -------------------------------------------------------------------------------- /codesignal/seats_in_threatrer: -------------------------------------------------------------------------------- 1 | /* 2 | https://app.codesignal.com/arcade/code-arcade/intro-gates/bszFiQAog96G9CXKg/solutions 3 | 4 | Given the total number of rows and columns in the theater (nRows and nCols, 5 | respectively), and the row and column you're sitting in, return the number of people 6 | who sit strictly behind you and in your column or to the left, assuming all seats are occupied. 7 | Example 8 | 9 | For nCols = 16, nRows = 11, col = 5, and row = 3, the output should be 10 | solution(nCols, nRows, col, row) = 96. 11 | 12 | */ 13 | 14 | int solution(int nCols, int nRows, int col, int row) { 15 | return (nCols- col+1)*(nRows-row); 16 | } 17 | -------------------------------------------------------------------------------- /codesignal/shapeArea.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codesignal/shapeArea.cpp -------------------------------------------------------------------------------- /codesignal/third_number.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | https://app.codesignal.com/arcade/code-arcade/at-the-crossroads/sgDWKCFQHHi5D3Szj/solutions 4 | third number 5 | You're given three integers, a, b and c. It is guaranteed that two of these integers are equal to each other. What is the value of the third integer? 6 | 7 | Example 8 | 9 | For a = 2, b = 7, and c = 2, the output should be 10 | solution(a, b, c) = 7. 11 | 12 | The two equal numbers are a and c. The third number (b) equals 7, which is the answer. 13 | 14 | 15 | */ 16 | 17 | int solution(int a, int b, int c) { 18 | if(a == b) 19 | return c; 20 | else if(a == c) 21 | return b; 22 | else 23 | return a; 24 | } 25 | -------------------------------------------------------------------------------- /codingblock/Manmohan-Loves-Patterns-I.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/Manmohan-Loves-Patterns-I.cpp -------------------------------------------------------------------------------- /codingblock/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/README.md -------------------------------------------------------------------------------- /codingblock/binary-to-decimal.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/binary-to-decimal.cpp -------------------------------------------------------------------------------- /codingblock/check-prime.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/check-prime.cpp -------------------------------------------------------------------------------- /codingblock/gdc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/gdc.cpp -------------------------------------------------------------------------------- /codingblock/geekforgeeks/README.md: -------------------------------------------------------------------------------- 1 | # GeeksForGeeks solutions 2 | [View GeeksForGeeks solutions here](https://github.com/omonimus1/geeks-for-geeks-solutions) 3 | -------------------------------------------------------------------------------- /codingblock/hello-codingblocks.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/hello-codingblocks.cpp -------------------------------------------------------------------------------- /codingblock/help_raul.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/help_raul.cpp -------------------------------------------------------------------------------- /codingblock/lower-Upper.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/lower-Upper.cpp -------------------------------------------------------------------------------- /codingblock/make-them-distinct.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/make-them-distinct.cpp -------------------------------------------------------------------------------- /codingblock/max-after-m-increments.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/max-after-m-increments.cpp -------------------------------------------------------------------------------- /codingblock/odd-and-even-back-in-Delhi.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/odd-and-even-back-in-Delhi.cpp -------------------------------------------------------------------------------- /codingblock/prime-visits.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/prime-visits.cpp -------------------------------------------------------------------------------- /codingblock/simple-input.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/simple-input.cpp -------------------------------------------------------------------------------- /codingblock/von-newumans-love-binary.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/codingblock/von-newumans-love-binary.cpp -------------------------------------------------------------------------------- /geeksforgeeks/README.md: -------------------------------------------------------------------------------- 1 | # GeeksForGeeks solutions 2 | [View GeeksForGeeks solutions here](https://github.com/omonimus1/geeks-for-geeks-solutions) 3 | -------------------------------------------------------------------------------- /hackerearth/Little-Jhool-and-psychic-powers.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/Little-Jhool-and-psychic-powers.cpp -------------------------------------------------------------------------------- /hackerearth/a+b.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/a+b.cpp -------------------------------------------------------------------------------- /hackerearth/a-movement.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/a-movement.cpp -------------------------------------------------------------------------------- /hackerearth/back-to-school.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/back-to-school.cpp -------------------------------------------------------------------------------- /hackerearth/char-sum.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/char-sum.cpp -------------------------------------------------------------------------------- /hackerearth/determining-numbers.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/determining-numbers.cpp -------------------------------------------------------------------------------- /hackerearth/doctor-secret.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/doctor-secret.cpp -------------------------------------------------------------------------------- /hackerearth/factorial.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/factorial.cpp -------------------------------------------------------------------------------- /hackerearth/i-am-easy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/i-am-easy.cpp -------------------------------------------------------------------------------- /hackerearth/life-universe-everything.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/life-universe-everything.cpp -------------------------------------------------------------------------------- /hackerearth/mistery.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/mistery.cpp -------------------------------------------------------------------------------- /hackerearth/palindrome.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/palindrome.cpp -------------------------------------------------------------------------------- /hackerearth/repeated-k-times.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/repeated-k-times.cpp -------------------------------------------------------------------------------- /hackerearth/simple-search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/simple-search.cpp -------------------------------------------------------------------------------- /hackerearth/two-strings.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/hackerearth/two-strings.cpp -------------------------------------------------------------------------------- /images/Insertion-sort-example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/Insertion-sort-example.gif -------------------------------------------------------------------------------- /images/bigocomplexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/bigocomplexity.png -------------------------------------------------------------------------------- /images/bubble-sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/bubble-sort.gif -------------------------------------------------------------------------------- /images/complete-tree.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/complete-tree.jpeg -------------------------------------------------------------------------------- /images/complexity-sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/complexity-sort.png -------------------------------------------------------------------------------- /images/complexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/complexity.png -------------------------------------------------------------------------------- /images/depency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/depency.png -------------------------------------------------------------------------------- /images/deuque.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/deuque.png -------------------------------------------------------------------------------- /images/diameter_of_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/diameter_of_tree.png -------------------------------------------------------------------------------- /images/fibonacci-heap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/fibonacci-heap.png -------------------------------------------------------------------------------- /images/graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/graph.png -------------------------------------------------------------------------------- /images/larghest-sum-contiguos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/larghest-sum-contiguos.png -------------------------------------------------------------------------------- /images/lca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/lca.png -------------------------------------------------------------------------------- /images/left_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/left_view.png -------------------------------------------------------------------------------- /images/lps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/lps.png -------------------------------------------------------------------------------- /images/matrices-multiplication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/matrices-multiplication.png -------------------------------------------------------------------------------- /images/merge-sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/merge-sort.gif -------------------------------------------------------------------------------- /images/mirror-tree.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/mirror-tree.jpeg -------------------------------------------------------------------------------- /images/perfect-binary-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/perfect-binary-tree.png -------------------------------------------------------------------------------- /images/quick-sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/quick-sort.gif -------------------------------------------------------------------------------- /images/selection-sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/selection-sort.gif -------------------------------------------------------------------------------- /images/sorting-complexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/sorting-complexity.png -------------------------------------------------------------------------------- /images/spanning-tree-tutorialpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/spanning-tree-tutorialpoint.png -------------------------------------------------------------------------------- /images/tree-depth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/tree-depth.png -------------------------------------------------------------------------------- /images/tree-views.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/tree-views.png -------------------------------------------------------------------------------- /images/types-of-edges.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/types-of-edges.png -------------------------------------------------------------------------------- /images/vertical_bt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/vertical_bt.png -------------------------------------------------------------------------------- /images/what.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/images/what.jpeg -------------------------------------------------------------------------------- /interviewbit/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/README.md -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/ReadMe.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/ReadMe.md -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/alphabet_pair.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/alphabet_pair.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/deque/deque.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/deque/deque.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/graph/breath-first-search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/graph/breath-first-search.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/graph/depth-first-search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/graph/depth-first-search.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/graph/detect-cycle.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/graph/detect-cycle.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/graph/unweighteGraph.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/graph/unweighteGraph.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/graph/weighted_graph.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/graph/weighted_graph.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/linkedList/LinkedListIntroduction.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/linkedList/LinkedListIntroduction.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/map/map_introductionn.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/map/map_introductionn.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/matrix/sumBetweenMatrix.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/matrix/sumBetweenMatrix.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/matrix/transposted.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/matrix/transposted.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/occurrency.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/occurrency.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/queue/QueueImplemenentation.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/queue/QueueImplemenentation.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/secret_code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/secret_code.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/set/set.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/set/set.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/stack/stack-Linked-list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/stack/stack-Linked-list.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/stack/stack.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/stack/stack.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/vectors/PalindromeVector.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/vectors/PalindromeVector.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/vectors/VectorIntroductions.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/vectors/VectorIntroductions.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c++/data-structures/vectors/two-smallest-in-list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c++/data-structures/vectors/two-smallest-in-list.cpp -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/HashTable.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/HashTable.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/array.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/array.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/binary_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/binary_search.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/challenge1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/challenge1.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/challenge2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/challenge2.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/challenge3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/challenge3.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/challenge4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/challenge4.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/deque.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/deque.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/doubly_linked_list.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/doubly_linked_list.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/exponential_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/exponential_search.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/grades.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/grades.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/graph.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/graph.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/interpolation_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/interpolation_search.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/jump_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/jump_search.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/lab03_data.structures.02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/lab03_data.structures.02.pdf -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/lab04_data.structures.03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/lab04_data.structures.03.pdf -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/lab05_data.structures.04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/lab05_data.structures.04.pdf -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/linear_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/linear_search.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/linked_list.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/linked_list.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/main.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/notes.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/notes.md -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/queue.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/queue.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/quicksort.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/quicksort.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/stack.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/stack.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/struct.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/struct.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/ternary.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/ternary.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/ternary_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/ternary_search.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/timing.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/timing.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/c/tree.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/c/tree.c -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/python/algorithm/gcd.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/python/algorithm/gcd.py -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/python/array.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/python/array.py -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/python/binarySearchTree.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/python/binarySearchTree.py -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/python/list_methods_implementation.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/python/list_methods_implementation.py -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/python/queue.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/python/queue.py -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/python/readMe.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/python/readMe.md -------------------------------------------------------------------------------- /interviewbit/learn_data_structures/python/stack.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/interviewbit/learn_data_structures/python/stack.py -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/ReadMe.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/ReadMe.md -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/alphabet_pair.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/alphabet_pair.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/deque/deque.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/deque/deque.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/graph/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/graph/a.out -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/graph/breath-first-search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/graph/breath-first-search.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/graph/depth-first-search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/graph/depth-first-search.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/graph/detect-cycle.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/graph/detect-cycle.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/graph/unweighteGraph.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/graph/unweighteGraph.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/graph/weighted_graph.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/graph/weighted_graph.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/linkedList/LinkedListIntroduction.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/linkedList/LinkedListIntroduction.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/map/map_introductionn.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/map/map_introductionn.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/matrix/sumBetweenMatrix.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/matrix/sumBetweenMatrix.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/matrix/transposted.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/matrix/transposted.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/occurrency.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/occurrency.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/queue/QueueImplemenentation.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/queue/QueueImplemenentation.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/secret_code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/secret_code.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/set/set.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/set/set.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/stack/stack-Linked-list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/stack/stack-Linked-list.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/stack/stack.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/stack/stack.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/vectors/PalindromeVector.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/vectors/PalindromeVector.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/vectors/VectorIntroductions.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/vectors/VectorIntroductions.cpp -------------------------------------------------------------------------------- /learn_data_structures/c++/data-structures/vectors/two-smallest-in-list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c++/data-structures/vectors/two-smallest-in-list.cpp -------------------------------------------------------------------------------- /learn_data_structures/c/HashTable.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/HashTable.c -------------------------------------------------------------------------------- /learn_data_structures/c/array.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/array.c -------------------------------------------------------------------------------- /learn_data_structures/c/binary_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/binary_search.c -------------------------------------------------------------------------------- /learn_data_structures/c/challenge1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/challenge1.c -------------------------------------------------------------------------------- /learn_data_structures/c/challenge2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/challenge2.c -------------------------------------------------------------------------------- /learn_data_structures/c/challenge3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/challenge3.c -------------------------------------------------------------------------------- /learn_data_structures/c/challenge4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/challenge4.c -------------------------------------------------------------------------------- /learn_data_structures/c/deque.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/deque.c -------------------------------------------------------------------------------- /learn_data_structures/c/doubly_linked_list.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/doubly_linked_list.c -------------------------------------------------------------------------------- /learn_data_structures/c/exponential_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/exponential_search.c -------------------------------------------------------------------------------- /learn_data_structures/c/grades.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/grades.c -------------------------------------------------------------------------------- /learn_data_structures/c/graph.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/graph.c -------------------------------------------------------------------------------- /learn_data_structures/c/interpolation_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/interpolation_search.c -------------------------------------------------------------------------------- /learn_data_structures/c/jump_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/jump_search.c -------------------------------------------------------------------------------- /learn_data_structures/c/lab03_data.structures.02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/lab03_data.structures.02.pdf -------------------------------------------------------------------------------- /learn_data_structures/c/lab04_data.structures.03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/lab04_data.structures.03.pdf -------------------------------------------------------------------------------- /learn_data_structures/c/lab05_data.structures.04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/lab05_data.structures.04.pdf -------------------------------------------------------------------------------- /learn_data_structures/c/linear_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/linear_search.c -------------------------------------------------------------------------------- /learn_data_structures/c/linked_list.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/linked_list.c -------------------------------------------------------------------------------- /learn_data_structures/c/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/main.c -------------------------------------------------------------------------------- /learn_data_structures/c/notes.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/notes.md -------------------------------------------------------------------------------- /learn_data_structures/c/queue.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/queue.c -------------------------------------------------------------------------------- /learn_data_structures/c/quicksort.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/quicksort.c -------------------------------------------------------------------------------- /learn_data_structures/c/stack.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/stack.c -------------------------------------------------------------------------------- /learn_data_structures/c/struct.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/struct.c -------------------------------------------------------------------------------- /learn_data_structures/c/ternary.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/ternary.c -------------------------------------------------------------------------------- /learn_data_structures/c/ternary_search.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/ternary_search.c -------------------------------------------------------------------------------- /learn_data_structures/c/timing.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/timing.c -------------------------------------------------------------------------------- /learn_data_structures/c/tree.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/c/tree.c -------------------------------------------------------------------------------- /learn_data_structures/python/algorithm/gcd.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/python/algorithm/gcd.py -------------------------------------------------------------------------------- /learn_data_structures/python/array.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/python/array.py -------------------------------------------------------------------------------- /learn_data_structures/python/binarySearchTree.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/python/binarySearchTree.py -------------------------------------------------------------------------------- /learn_data_structures/python/list_methods_implementation.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/python/list_methods_implementation.py -------------------------------------------------------------------------------- /learn_data_structures/python/queue.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/python/queue.py -------------------------------------------------------------------------------- /learn_data_structures/python/readMe.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/python/readMe.md -------------------------------------------------------------------------------- /learn_data_structures/python/stack.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/learn_data_structures/python/stack.py -------------------------------------------------------------------------------- /must-do-exercises/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/must-do-exercises/README.md -------------------------------------------------------------------------------- /must-do-exercises/arrays/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/must-do-exercises/arrays/a.out -------------------------------------------------------------------------------- /must-do-exercises/arrays/number_of_pairs.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/must-do-exercises/arrays/number_of_pairs.cpp -------------------------------------------------------------------------------- /must-do-exercises/arrays/sort-array-of-0-and-1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/must-do-exercises/arrays/sort-array-of-0-and-1.cpp -------------------------------------------------------------------------------- /must-do-exercises/linked-list/get-middle-element.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/must-do-exercises/linked-list/get-middle-element.cpp -------------------------------------------------------------------------------- /must-do-exercises/linked-list/nth-node-from-end.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/must-do-exercises/linked-list/nth-node-from-end.cpp -------------------------------------------------------------------------------- /spoj/1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/spoj/1.cpp -------------------------------------------------------------------------------- /spoj/24.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omonimus1/competitive-programming/e657e77e4cba35f56245ff3ef89b453d0e30044c/spoj/24.cpp -------------------------------------------------------------------------------- /spoj/ABSP1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | ll n; 22 | cin>>n; 23 | ll a[n]; 24 | fo(i,n) 25 | cin>>a[i]; 26 | ll sum=0; 27 | for(ll i=0;i 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | for(int i=0;i>n; 23 | while(n%2==0) 24 | { 25 | n/=2; 26 | } 27 | cout<<"Case "<<(i+1)<<": "< 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | ll n; 22 | cin>>n; 23 | 24 | ll a[]={1,4,6,5,2,0}; 25 | cout<<(a[(n-1)%6])<<"\n"; 26 | 27 | } 28 | 29 | 30 | return 0; 31 | } 32 | /******************************************************* 33 | WRONG QUESTION(ERROR) 34 | **********************************************************/ -------------------------------------------------------------------------------- /spoj/MOHIB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | ll x,a; 22 | cin>>x>>a; 23 | ll n=a-x; 24 | ll sum=n*(a+1); 25 | sum=sum-n*(n-1)/2; 26 | cout< 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | for(int i=0;i>n; 23 | 24 | if(n<3) 25 | ans=0; 26 | else 27 | ans=sqrt(1+n)-1; 28 | cout<<"Case "<<(i+1)<<": "< 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | double a,b,c,d; 22 | cin>>a>>b>>c>>d; 23 | 24 | double sp=(a+b+c+d)/2; 25 | double area=sqrt((sp-a)*(sp-b)*(sp-c)*(sp-d)); 26 | 27 | cout< 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i0) 15 | { 16 | digsum+=n%10; 17 | n/=10; 18 | } 19 | return digsum; 20 | } 21 | 22 | int main() { 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt", "r", stdin); 25 | freopen("output.txt", "w", stdout); 26 | #endif 27 | fast_io 28 | 29 | ll t; 30 | cin>>t; 31 | while(t--) 32 | { 33 | ll n; 34 | cin>>n; 35 | while((n%sum(n))!=0) 36 | { 37 | n++; 38 | } 39 | cout< 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | ll n;cin>>n; 22 | 23 | if(n%2) 24 | cout<<0<<"\n"; 25 | else 26 | cout<<1<<"\n"; 27 | 28 | } 29 | 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /spoj/crds.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | ll n; 22 | cin>>n; 23 | 24 | ll MOD=1000007; 25 | 26 | //ll ans=((((n%MOD)*(n%MOD)*(n%MOD))%MOD + ((n%MOD)*(n%MOD))%MOD -(2*(n%MOD))%MOD))/2%MOD; 27 | ll ans=(((3*(n%MOD)*(n%MOD))+(n%MOD))/2)%MOD; 28 | 29 | cout< 2 | #define ll long long int 3 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 4 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 5 | #define MOD 1000000007 6 | #define pb push_back 7 | #define fo(i,n) for(ll i=0;i>t; 16 | while(t--) 17 | { 18 | tem = 0;; 19 | cin >> x; 20 | if (x % 2 != 0) 21 | { 22 | cout << x << endl; 23 | continue; 24 | } 25 | 26 | while (x != 0) 27 | { 28 | tem = tem << 1; 29 | tem = tem + (x & 1); 30 | x = x >> 1; 31 | 32 | } 33 | cout << tem << endl; 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /spoj/fctrl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | ll n,ans=0; 22 | cin>>n; 23 | for(ll i=5;n/i>=1;i*=5) 24 | { 25 | ans+=n/i; 26 | } 27 | cout< 2 | #include 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i1; --i) 16 | fact *= i; 17 | return fact; 18 | } 19 | 20 | 21 | int main() { 22 | #ifndef ONLINE_JUDGE 23 | freopen("input.txt", "r", stdin); 24 | freopen("output.txt", "w", stdout); 25 | #endif 26 | fast_io 27 | 28 | ll t; 29 | cin>>t; 30 | while(t--) 31 | { 32 | ll n; 33 | cin>>n; 34 | cout< 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | 22 | } 23 | 24 | 25 | return 0; 26 | } 27 | 28 | 29 | // TO DO -------------------------------------------------------------------------------- /spoj/ieeeeebgam.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long int 4 | #define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging 5 | #define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also 6 | #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); 7 | #define fo(i,n) for(ll i=0;i>t; 19 | while(t--) 20 | { 21 | int n; 22 | cin>>n; 23 | 24 | double m=n; 25 | double ans=m/(m+1); 26 | cout<