├── .DS_Store ├── .vscode ├── launch.json └── settings.json ├── 2d.py ├── Amrith.class ├── Amrith.java ├── CODECHEF ├── April-CookOFF │ ├── a.out │ ├── problem1.cpp │ ├── problem3.cpp │ └── rundir.cpp ├── Coders-Legacy │ ├── a.out │ ├── fib_str.cpp │ ├── kill_zombie.cpp │ ├── sum_primes.cpp │ └── useless_clock.cpp ├── DP │ ├── a.out │ ├── alternating_sub.cpp │ └── dessert_wizard.cpp ├── Dementia │ ├── a.out │ ├── exodia.cpp │ ├── pappu_dfs.cpp │ ├── replication.cpp │ └── strings.cpp ├── Heaps │ └── IPCTrain.cpp ├── Long-April │ ├── a.out │ ├── avg_pairs.cpp │ ├── chef_par.cpp │ ├── cherpar.py │ ├── count_prefixes.cpp │ ├── cutting_plants.cpp │ ├── highway_crossing.cpp │ ├── vaibhav.cpp │ ├── weighted_num.cpp │ └── workers.cpp ├── Long-May │ ├── a.out │ └── dib_fib.cpp ├── May-CookOFF │ ├── a.out │ ├── bestcake.cpp │ └── prob1.cpp ├── Mock-1 │ ├── a.out │ ├── alter_subarray.cpp │ ├── count_subs.cpp │ ├── lapindrome.cpp │ ├── max_weight_diff.cpp │ └── mutated_minors.cpp ├── Mock-2 │ ├── a.out │ └── stacks.cpp ├── Sept-Long │ ├── a.out │ ├── binary_shuffle.cpp │ ├── chef_adv.cpp │ ├── chef_magician.cpp │ └── war_of_xors.cpp └── Stacks │ ├── COMPILER.cpp │ ├── HISTOGRA.cpp │ ├── MMASS.cpp │ ├── NEXT_PERUMTE.cpp │ ├── ONP.cpp │ ├── STPAR.cpp │ └── a.out ├── Clap └── Primes │ ├── a.out │ ├── input.txt │ ├── ip2.txt │ ├── output.txt │ └── prime.cpp ├── Codejam ├── a.out ├── go_gopher.cpp ├── save_the_universe.cpp └── trouble_sort.cpp ├── Coding-Ninjas ├── .DS_Store ├── .vscode │ └── tasks.json ├── Assignment-1 │ ├── a.out │ ├── extract_unique_characters.cpp │ ├── kth-largest.cpp │ ├── longest_consecutive_subsequence.cpp │ └── stock_span.cpp ├── Assignment-2-Adv_Rec │ ├── .DS_Store │ ├── binary_search.cpp │ ├── check_abb.cpp │ ├── print_all_codes.cpp │ ├── print_permutation.cpp │ ├── print_subset.cpp │ ├── print_subset_sum_k.cpp │ ├── return_all_codes_string.cpp │ ├── return_permutation.cpp │ ├── return_subset_array.cpp │ ├── return_subset_sum_to_k.cpp │ └── staircase.cpp ├── Assignment-3-BackTrack │ ├── a.out │ ├── distribute_candidates.cpp │ ├── find_power.cpp │ ├── murder.cpp │ └── sudoku_solver.cpp ├── Assignment-4-Number-Theory │ ├── a.out │ ├── card_game.cpp │ ├── find_cube.cpp │ ├── find_good_sets.cpp │ ├── n_factorful.cpp │ ├── strange_order.cpp │ └── strange_order_optim.cpp ├── Assignment-5-Mixed │ ├── a.out │ ├── divisible_41.cpp │ ├── monk_and_cakes.cpp │ ├── professors_assignment.cpp │ ├── toll_gate.cpp │ └── word_break-1.cpp ├── Assignment-6-1-DP │ ├── a.out │ ├── all_ways_power.cpp │ ├── coin_change.cpp │ ├── coin_tower.cpp │ ├── lis.cpp │ ├── lis_nlogn.cpp │ ├── loot_hourses.cpp │ └── matrix_chain.cpp ├── Assignment-6-Number-Theory-2 │ ├── a.out │ ├── cubic_sqr.cpp │ ├── devasena.cpp │ ├── gcd_extreme.cpp │ ├── innocent_swaps.cpp │ ├── sanchit_nuclear_reactor.cpp │ └── sehwag_and_etf.cpp ├── Assignment-7-Dynamic-Programming-1 │ ├── a.out │ ├── adjacent_bit_count.cpp │ ├── alonya_and_spreadsheet.cpp │ ├── angry_children.cpp │ ├── hasan_and_trip.cpp │ ├── jon_snow.cpp │ ├── roy_and_coin_boxes.cpp │ └── vanya_and_gcd.cpp ├── Assignment-8-Dynamic-Programming-2 │ ├── a.out │ ├── charlier_and_pilots.cpp │ ├── distinct_subsequences.cpp │ ├── miser_man.cpp │ ├── pussycat_sonya.cpp │ ├── square_brackets.cpp │ ├── star_sky.cpp │ ├── sum_of_digits.cpp │ └── trader_profit.cpp ├── Assignment-9-Fenwick-Trees │ └── gcd_query.cpp ├── Basic_Recursion │ ├── a.out │ ├── all_indexes.cpp │ ├── array_sum.cpp │ ├── check_number.cpp │ ├── first_index.cpp │ ├── last_index.cpp │ ├── number_of_digits.cpp │ └── power.cpp ├── Lecture-1 │ ├── non_repeating_char_ON.cpp │ └── remove_duplicates_ON.cpp ├── Lecture-10-Fenwick-Trees │ ├── a.out │ ├── basic_operations_bit.cpp │ ├── coder_rating.cpp │ ├── distinct_queries.cpp │ └── order_set.cpp ├── Lecture-11-Dynamic-Programming-3 │ ├── a.out │ ├── bit_masking.cpp │ ├── candy.cpp │ ├── ghost_type.cpp │ ├── matrix_chain_mult.cpp │ └── mixtures.cpp ├── Lecture-12-Graphs-2 │ ├── a.out │ ├── dijkstras_algo.cpp │ ├── dijkstras_priority_queue.cpp │ ├── kruskal_better.cpp │ ├── kruskal_mst.cpp │ ├── prims_mst.cpp │ └── union_find_rank_path.cpp ├── Lecture-13-Advanced-Graphs │ ├── CAPCITY_OP.cpp │ ├── FILLMTR.cpp │ ├── a.out │ ├── airports_correct.cpp │ ├── airports_wrong.cpp │ ├── bipartite.cpp │ ├── bottom_of_the_graph.cpp │ ├── bugs_life.cpp │ ├── capital_city.cpp │ ├── connected_comp.cpp │ ├── connected_horses.cpp │ ├── dominos.cpp │ ├── fill_the_matrix.cpp │ ├── kingdom_of_monkeys.cpp │ ├── monk_and_islands.cpp │ ├── new_year_transport.cpp │ ├── permutation_swaps.cpp │ ├── scc.cpp │ └── space_smugglers.cpp ├── Lecture-14-Mixed-Problems │ ├── JP_and_Plan.cpp │ ├── JP_dfs.cpp │ ├── a.out │ ├── birthday_bash.cpp │ ├── comrade.cpp │ ├── costly_phone_num.cpp │ ├── equal_numbers.cpp │ ├── gcd_matrix.cpp │ ├── just_shortest.cpp │ └── tree_divisors.cpp ├── Lecture-16-Greedy │ ├── a.out │ ├── activity_selection.cpp │ ├── fractional_knapsack.cpp │ ├── himani_and_stocks.cpp │ ├── karan_at_the_pg.cpp │ ├── min_abs_diff.cpp │ ├── nikunj_and_donuts.cpp │ ├── wall_paint.cpp │ ├── weighted_jobs.cpp │ └── weighted_jobs_op.cpp ├── Lecture-17-Tries │ ├── a.out │ └── max_xor_pair.cpp ├── Lecture-18-CG │ ├── a.out │ └── area_polygon.cpp ├── Lecture-2-Adv_rec │ ├── a.out │ ├── merge_sort.cpp │ ├── print_keypad_code.cpp │ ├── print_subsequence.cpp │ ├── quick_sort.cpp │ ├── remove_duplicates.cpp │ ├── replace_char.cpp │ ├── return_keypad.cpp │ └── subsequence.cpp ├── Lecture-3-BackTracking │ ├── N-Queen.cpp │ ├── a.out │ ├── aggressive_cow.cpp │ ├── inversion_count.cpp │ ├── n_queen_prac.cpp │ └── rat_in_a_maze.cpp ├── Lecture-4-Number-Theory │ ├── a.out │ ├── advanced_gcd.cpp │ ├── balanced_bin_tree.cpp │ ├── divisor_of_factorial.cpp │ ├── extended_euclid.cpp │ ├── find_prime_n.cpp │ ├── gcd.cpp │ └── sachin_and_varun.cpp ├── Lecture-5-Number-Theory-2 │ ├── a.out │ ├── a_power_b_mod_c.cpp │ ├── boring_factorials.cpp │ ├── euler_totient.cpp │ ├── fibonacci_sum.cpp │ ├── income_nth_day.cpp │ ├── lcm_sum.cpp │ ├── nth_fib_no.cpp │ └── segmented_sieve.cpp ├── Lecture-6-Dynamic-Programming │ ├── a.out │ ├── alpha_code.cpp │ ├── coin_change.cpp │ ├── coin_change_submitted.cpp │ ├── fibonacci_dp.cpp │ ├── keypad_code_dp.cpp │ ├── largest_bitonic_subarray.cpp │ ├── lis.cpp │ ├── magic_grid.cpp │ ├── max_sum_subarray.cpp │ ├── maximum_sum_rectangle.cpp │ ├── min_cost.cpp │ ├── number_r.cpp │ ├── princess_farida.cpp │ └── staircase.cpp ├── Lecture-7-Dynamic-Progamming-2 │ ├── a.out │ ├── balika_vadhu.cpp │ ├── edit_distance.cpp │ ├── knapsack.cpp │ ├── knapsack_iterative.cpp │ ├── lcs_dp.cpp │ ├── lcs_iterative.cpp │ ├── party.cpp │ ├── prime_xor.cpp │ ├── subset_sum.cpp │ └── subset_sum_iter.cpp ├── Lecture-8-Segment-Trees │ ├── 2vs3.cpp │ ├── a.out │ ├── basic_operations_segment_tree.cpp │ ├── even_or_odd.cpp │ ├── horrible_queries.cpp │ ├── lazy_propagation.cpp │ ├── max_pair_sum.cpp │ ├── max_sum_subarray.cpp │ ├── range_min_queries.cpp │ ├── segTree_lazy.cpp │ ├── seqsqrss.cpp │ ├── sum_of_squares.cpp │ └── vasya_and_rhezo.cpp ├── Lecture-9-Graphs │ ├── a.out │ ├── bfs.cpp │ ├── bfs_disconnected.cpp │ ├── dfs.cpp │ ├── dfs_disconnected.cpp │ ├── get_path_bfs.cpp │ ├── get_path_dfs.cpp │ ├── has_path.cpp │ ├── isConnected.cpp │ └── return_connected_comp.cpp ├── Test-2 │ ├── a.out │ ├── fisher_monger.cpp │ ├── free_code.cpp │ └── super_number.cpp ├── a.out ├── array_pointer.cpp └── strange_nirmal.cpp ├── DAA-2.zip ├── DAA-2 ├── a.out ├── dfs ├── dfs_cc.cpp ├── disjoint_set_adt.cpp ├── disjoint_set_cc.cpp ├── djset ├── graph_tc_gen.cpp ├── input.txt ├── output1.txt ├── output2.txt └── plotter.py ├── Data-Structures ├── .vscode │ └── launch.json ├── BTrees │ ├── a.out │ └── basics.cpp ├── Binary-Trees │ ├── a.out │ ├── binary_tree_lca.cpp │ ├── binary_tree_symmetry.cpp │ ├── bt_implementation_ll.cpp │ ├── bt_inOrder_stack.cpp │ ├── bt_level_line.cpp │ ├── bt_preOrder_iter.cpp │ ├── bt_reverse_levelorder.cpp │ └── root_leaf_binary_sum.cpp ├── Binary_Search_Trees │ ├── a.out │ ├── binary_tree_to_bst.cpp │ ├── bst_from_preorder.cpp │ ├── bst_implementation.cpp │ ├── bst_pred_suc.cpp │ ├── bt_isBalanced.cpp │ └── greater_sum_bst_to_bt.cpp ├── Graphs │ ├── a.out │ ├── basic_graphs.cpp │ ├── graph_adj_list.cpp │ └── iter.cpp ├── Heaps │ ├── a.out │ ├── heap_sort.cpp │ ├── max_heap.cpp │ └── priority_queue.cpp ├── Linked-Lists │ ├── a.out │ ├── loop_detection.cpp │ ├── merge_two_sorted.cpp │ ├── merge_two_sorted_inplace.cpp │ ├── nth_node_from_end.cpp │ ├── palindrome_ll.cpp │ └── reverse_ll.cpp ├── Test.class ├── Test.java ├── Tree.class ├── Trees │ ├── a.out │ ├── practice_trees.cpp │ ├── topview.cpp │ ├── tree.cp │ └── tree.cpp ├── a.out ├── bitmanip.cpp ├── detect_remove_loop_ll.cpp ├── dynamic_array.cpp └── tree.java ├── Debug.zip ├── Debug ├── Divisors-of-Factorial │ ├── Problem.txt │ └── div_of_fact.cpp ├── N-Queen │ ├── Problem.txt │ └── n_queen.cpp ├── Subsets-In-Array │ ├── Problem.txt │ └── subsets.cpp └── a.out ├── Goldman-Sachs ├── _type ├── a.out ├── arr[0][t_i] ├── arr[1][p_i] ├── bank_accounts.cpp ├── buy_max_stock.cpp ├── currencies.py ├── time_series_query.cpp ├── time_series_query_map.cpp ├── trader_profit.cpp └── v ├── Graph.class ├── Graph.java ├── Hash-Combat ├── a.out ├── p1.cpp ├── p2.cpp └── p3.cpp ├── HourRank23 ├── a.out └── ques1.cpp ├── Quest-Python ├── account.py ├── custom_thread.py ├── file.py ├── read_write.py ├── stud.pickle └── test.txt ├── README.md ├── SOPC-18 ├── a.out ├── assgn.cpp ├── smile.cpp ├── superman.cpp └── villain.cpp ├── Searching ├── connected_cell_grid.cpp ├── gridland_metro.cpp ├── knightL_chessboard.cpp ├── max_sub_mod_m.cpp ├── min_loss_better.cpp ├── minimum_loss_1.cpp ├── pairs_sol1.cpp ├── red_knight_shortest.cpp └── sherlock_and_array.cpp ├── Solutions.zip ├── Solutions ├── divisor_of_factorial_sol.cpp ├── n_queen_sol.cpp └── subsets_sol.cpp ├── TRIUMPH ├── Assignment-0-Patterns │ ├── a.out │ ├── arrow_pattern.cpp │ ├── matrix_order_pattern.cpp │ ├── number_pattern.cpp │ ├── number_pattern_5.cpp │ ├── number_pattern_grid.cpp │ └── triangle_patterns.cpp ├── Assignment-2-Arrays-Strings │ ├── a.out │ ├── break_words.cpp │ ├── count_palindromic.cpp │ ├── count_platforms.cpp │ ├── largest_unique_subs.cpp │ ├── leaders_in_array.cpp │ ├── matrix_spiral.cpp │ ├── push_zeroes.cpp │ ├── reverse_words.cpp │ ├── sort_012.cpp │ ├── sort_012_DNF.cpp │ └── wave_print.cpp ├── Assignment-3-HashMaps │ ├── a.out │ ├── array_intersection.cpp │ ├── highest_freq.cpp │ ├── longest_0_1.cpp │ ├── longest_consec_subs.cpp │ ├── make_anagrams.cpp │ ├── min_repeat_dist.cpp │ ├── pairSum_zero.cpp │ └── verticalOrder.cpp ├── Lecture-10-LL-1 │ ├── delete_ith.cpp │ ├── delete_recursive.cpp │ ├── divide_alternating.cpp │ ├── even_after_odd.cpp │ ├── insert_recursive.cpp │ ├── length_iter.cpp │ ├── ll_palin_mylogic.cpp │ ├── move_last_first.cpp │ ├── print_ith.cpp │ ├── reverse_k_group.cpp │ ├── skipMdeleteN.cpp │ └── swap_nodes.cpp ├── Lecture-11-LL-2 │ ├── a.out │ ├── merge_sort.cpp │ ├── merge_sorted_ll.cpp │ ├── midpoint_ll.cpp │ └── reverseLL_recursive.cpp ├── Lecture-12-Stacks-Queues │ ├── a.out │ ├── infix_to_postfix.cpp │ ├── isBalanced.cpp │ ├── queue_ll.cpp │ ├── sort_stack.cpp │ ├── stack_array.cpp │ ├── stack_ll.cpp │ └── template_pair.cpp ├── Lecture-13-Trees │ ├── TreeNode.cpp │ ├── a.out │ └── levelWise.cpp ├── Lecture-14-BinaryTree │ ├── acm_icpc.cpp │ ├── height.cpp │ ├── levelwise_ll.cpp │ ├── min_and_max.cpp │ ├── mirror_bt.cpp │ ├── node_present.cpp │ └── print_level.cpp ├── Lecture-15-BST │ ├── a.out │ ├── avl_tree_imp.cpp │ ├── bstClass.cpp │ ├── bst_from_array.cpp │ ├── bst_submit.cpp │ ├── bst_to_ll.cpp │ ├── elem_k1_k2.cpp │ ├── isBST.cpp │ ├── path_in_bst.cpp │ └── search_elem.cpp ├── Lecture-16-PriorityQ │ ├── MERGE_K_SORT.cpp │ ├── RUNNING_MEDIAN.cpp │ ├── a.out │ ├── check_max_heap.cpp │ ├── heap_sort.cpp │ ├── k_largest_nlogk.cpp │ ├── k_smallest_nlogk.cpp │ ├── k_sorted_array.cpp │ ├── max_pq_class.cpp │ └── remove_min.cpp ├── Lecture-17-Tries-Huffman │ ├── a.out │ ├── huffman_coding.cpp │ ├── input_huffman.txt │ ├── trieNode_self.cpp │ └── tries_imp.cpp ├── Lecture-2-Arrays │ ├── a.out │ ├── find_dup_n-2.cpp │ ├── find_max_path.cpp │ └── recover_array.cpp ├── Lecture-5-Rec-1 │ ├── a.out │ └── x_power_n.cpp ├── Lecture-6-Rec-2 │ ├── a.out │ ├── interleaving.cpp │ ├── keypad_print.cpp │ ├── min_count.cpp │ ├── print_subseq.cpp │ ├── quicksort.cpp │ ├── replace_pi.cpp │ ├── ret_subseq.cpp │ └── return_keypad.cpp └── Lecture-8-OOPS-1 │ ├── Student.cpp │ ├── a.out │ └── studentUse.cpp ├── Templates ├── HashMap │ ├── HashMap.h │ ├── HashNode.h │ └── KeyHash.h └── SegTree │ └── segtree.cpp ├── V ├── WIC-PreXtreme ├── a.out ├── akbar.cpp ├── akbar.py ├── akbarcpp ├── annabelle.cpp ├── aravinda.cpp ├── lost_love.cpp ├── megha.cpp ├── palindrome.cpp └── pens.cpp ├── Week-Of-Code-35 ├── highway_constr.cpp ├── highway_constr.py ├── matrix_land.cpp └── surface_area_3d.cpp ├── Week-Of-Code-37 ├── a.out ├── jim_2.cpp ├── two_eff_teams.cpp ├── twoteam.cpp ├── z_fn.cpp └── zf.cpp ├── World-Codesprint12 ├── a.out ├── animal_transport.cpp ├── breaking_sticks.cpp ├── fact_arr_segTree.cpp ├── factorial_array.cpp ├── lazy_fact.cpp └── redknight.cpp ├── Zoho-Practice ├── a.out └── alternate_sort.cpp ├── a.java ├── a.out ├── absolute_permutation.cpp ├── accs.py ├── accsort.py ├── alternating_char.cpp ├── anagram.cpp ├── app.py ├── append_delete.cpp ├── apple.c ├── arr[arr_i] ├── b ├── bad_dream.cpp ├── baker.cpp ├── baker_problem.cpp ├── basics.cpp ├── bday_chocolate.cpp ├── beautiful_binary_string.cpp ├── beautiful_triplets.cpp ├── beauty.py ├── between_two_sets.cpp ├── bfs.py ├── bigger_greater.cpp ├── bigger_greater_labyrinth.cpp ├── binaryString_max1s.cpp ├── bomberman.cpp ├── breaking_sticks.py ├── caesar-cipher.cpp ├── can_cons.cpp ├── candies.cpp ├── candies_dp.cpp ├── cavity_map.cpp ├── caw1.cpp ├── chocolate_feast.cpp ├── circular_array.cpp ├── climb_leaderboard.cpp ├── climb_leaderboard_comp.cpp ├── codevita ├── a.out ├── peppermint.cpp ├── peppermint.py ├── permute.cpp ├── permute.py └── seq.cpp ├── codevita2 ├── build.py ├── building.cpp └── buildings.py ├── codiva ├── camera_purchase.cpp ├── mini_maxi.cpp └── prime_queries.cpp ├── coin_change.cpp ├── cost_of_merging.cpp ├── count_walks.cp ├── count_walks.cpp ├── cp.cpp ├── cut_stick.cpp ├── determining_dna_health.cpp ├── dijk.c ├── dijkstra.py ├── dijkstra_shortest_2.cpp ├── dijkstras.c ├── dir.c ├── dir.py ├── elec.py ├── electo.cpp ├── emas_supercomputer.cpp ├── encryption.cpp ├── eq.cpp ├── equal.cpp ├── eval01ABC.cpp ├── even_tree.cpp ├── extract_unique_characters.cpp ├── factorial_power_div.cpp ├── fair_rations.cpp ├── fibonacci_modified.cpp ├── find_all_paths.cpp ├── find_closest_n_div_m.cpp ├── find_next_permutation.cpp ├── flatland_space.cpp ├── freq.cpp ├── funny_string.cpp ├── game_of_thrones_1.cpp ├── gemStones.cpp ├── gopher.cpp ├── grid_challenge.c ├── grid_challenge.cpp ├── grid_search.cpp ├── hackerland_radio.cpp ├── hackerrank_in_a_string.cpp ├── happy_ladybugs.cpp ├── helloworld.cpp ├── help_ferb.cpp ├── icecream_parlour.cpp ├── infinity_code ├── a.out ├── n ├── p1.cpp ├── p3.cpp ├── p3.py ├── q ├── soul.py ├── t ├── task[i].di ├── task[i].ki ├── task[i].ti └── timestone.cpp ├── insertion_sort-1.cpp ├── intro_to_nim.cpp ├── journey_to_the_moon.cpp ├── jump_cloud.cpp ├── jump_clouds_revisited.cpp ├── kmst.cpp ├── knapsack_unbounded.cpp ├── kruskal_mst.cpp ├── kruskals_matrix.cpp ├── laptop.cpp ├── larrys_arrays.cpp ├── library_fine.cpp ├── lisas_workbook.cpp ├── longest_increasing_subsequence_dp.cpp ├── love_letter_mystery.cpp ├── magicSquare.cpp ├── make_anagrams.cpp ├── manasa_stones.cpp ├── marcs_cakewalk.cpp ├── matrix.c ├── max_length_palin.cpp ├── max_product_subarray.cpp ├── maximum_subarray.cpp ├── min_abs_diff.cpp ├── minimum_dist.cpp ├── missing_numbers.cpp ├── modified_kaprekar.cpp ├── n ├── new.c ├── non_divisible_subset.cpp ├── npat ├── Untitled-1 ├── a.out ├── q3.cpp ├── q4.cpp ├── q5.cpp ├── q6.cpp ├── q7.cpp ├── q8.cpp └── q82.cpp ├── organizing_balls.cpp ├── p.py ├── p1.c ├── palindrom_index.cpp ├── parity_game.cpp ├── password_cracker.cpp ├── path_with_k_edges.cpp ├── pattern.py ├── permutations.cpp ├── pgm1.py ├── pick.py ├── pick_numbers.cpp ├── power_sum_recursion.cpp ├── prims_mst.cpp ├── progday.py ├── q ├── q8.cpp ├── queen.py ├── queens_attack.py ├── queens_attack_2.cpp ├── ques2.cpp ├── recursive_digit_sum.cpp ├── rep_strings.cpp ├── roadsandlib.py ├── s ├── segtree.cpp ├── sentence_eq.cpp ├── separate-the-nos.cpp ├── service_lane.cpp ├── sherlock_and_anagrams.cpp ├── sherlock_and_cost.cpp ├── sherlock_and_the_valid_string.cpp ├── simple_dfs.cpp ├── snake_and_ladder.cpp ├── snake_and_ladder_sol.cpp ├── strange_counter.cpp ├── string_construction.cpp ├── sum_vs_xor.cpp ├── super_mancunian.cpp ├── super_reduced_string.cpp ├── super_reduced_string.py ├── taum_bday.cpp ├── tech.cpp ├── test.py ├── time_in_words.cpp ├── time_series.py ├── two_characters.cpp ├── two_strings.cpp ├── weighted_uniform_string.cpp ├── winning_comp.cpp ├── winter_839d.py ├── xor.cpp └── xor.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/.DS_Store -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdb) Launch", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "program": "enter program name, for example ${workspaceRoot}/a.out", 9 | "args": [], 10 | "stopAtEntry": false, 11 | "cwd": "${workspaceRoot}", 12 | "environment": [], 13 | "externalConsole": true, 14 | "MIMode": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /2d.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | 6 | arr = [] 7 | for arr_i in xrange(6): 8 | arr_temp = map(int,raw_input().strip().split(' ')) 9 | arr.append(arr_temp) 10 | hrGlass=[] 11 | for arr_i in xrange(4): 12 | arr_temp = [0,0,0,0] 13 | hrGlass.append(arr_temp) 14 | for i in range(0,4): 15 | for j in range(0,4): 16 | hrGlass[i][j]=arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2] 17 | #print hrGlass 18 | maxSum=hrGlass[0][0] 19 | for i in range(0,4): 20 | for j in range(0,4): 21 | if(hrGlass[i][j]>maxSum): 22 | maxSum=hrGlass[i][j] 23 | print maxSum 24 | 25 | -------------------------------------------------------------------------------- /Amrith.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Amrith.class -------------------------------------------------------------------------------- /Amrith.java: -------------------------------------------------------------------------------- 1 | import java.lang.*; 2 | class Amrith 3 | { 4 | public static void main(String args[]) 5 | { 6 | System.out.println(args[0]+" "+args[1]); 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /CODECHEF/April-CookOFF/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/April-CookOFF/a.out -------------------------------------------------------------------------------- /CODECHEF/Coders-Legacy/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Coders-Legacy/a.out -------------------------------------------------------------------------------- /CODECHEF/Coders-Legacy/kill_zombie.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /CODECHEF/Coders-Legacy/useless_clock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | 9 | while(t--) 10 | { 11 | int n; 12 | float p,q; 13 | cin >> p >> q >> n; 14 | 15 | int coin_hrs = abs(ceil((12*q)/(float)(p-q))); 16 | // cout << "\nCH: " << coin_hrs << endl; 17 | if(coin_hrs % 12 == 0) 18 | { 19 | cout << ((n-1)*coin_hrs)/24 +1 << endl; 20 | } 21 | else 22 | { 23 | cout << ceil((n*coin_hrs)/24) << endl; 24 | } 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /CODECHEF/DP/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/DP/a.out -------------------------------------------------------------------------------- /CODECHEF/Dementia/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Dementia/a.out -------------------------------------------------------------------------------- /CODECHEF/Dementia/exodia.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Node 5 | { 6 | int a,b,c,id 7 | }; 8 | 9 | int main() 10 | { 11 | int n,m,k; 12 | cin >> n >> m >> k; 13 | unordered_map idMap; 14 | 15 | 16 | int id = 0; 17 | for(int i = 0; i < k; i++) 18 | { 19 | string s; 20 | int a,b,c; 21 | cin >> a >> b >> c >> s; 22 | 23 | if(idMap[s] == idMap.end()) 24 | idMap[s] = id++; 25 | 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /CODECHEF/Dementia/replication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define LL long long int 5 | 6 | int main() 7 | { 8 | int t; 9 | cin >> t; 10 | 11 | while(t--) 12 | { 13 | LL n,k; 14 | cin >> n >> k; 15 | 16 | unordered_map countMap; 17 | for(int i = 0; i < n; i++) 18 | { 19 | LL x; 20 | cin >> x; 21 | 22 | countMap[x]++; 23 | } 24 | 25 | LL sum = 0; 26 | 27 | for(auto it : countMap) 28 | { 29 | if(it.second == k) 30 | { 31 | sum += it.first; 32 | } 33 | } 34 | 35 | if(sum == 0) 36 | { 37 | cout << -1 << endl; 38 | continue; 39 | } 40 | else 41 | cout << sum << endl; 42 | } 43 | return 0; 44 | } -------------------------------------------------------------------------------- /CODECHEF/Dementia/strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s; 7 | cin >> s; 8 | 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /CODECHEF/Heaps/IPCTrain.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Lect 5 | { 6 | int tr; 7 | int day; 8 | int sad; 9 | }; 10 | 11 | bool compare(Lect l1,Lect l2) 12 | { 13 | return l1.sad > l2.sad; 14 | } 15 | 16 | int main() 17 | { 18 | 19 | ios_base::sync_with_stdio(false); 20 | 21 | int t; 22 | cin >> t; 23 | while(t--) 24 | { 25 | int n,d; 26 | cin >> n >> d; 27 | Lect *lec = new Lect[n]; 28 | for(int i = 0; i < n; i++) 29 | { 30 | cin >> lec[i].day >> lec[i].tr >> lec[i].sad; 31 | } 32 | sort(lec,lec+n,compare); 33 | 34 | 35 | 36 | } 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /CODECHEF/Long-April/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Long-April/a.out -------------------------------------------------------------------------------- /CODECHEF/Long-April/cherpar.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | n,m,k = map(int,raw_input().split()) 4 | arr = map(int,raw_input().split()) 5 | primes = map(int,raw_input().split()) 6 | 7 | max_val = 0 8 | best_arr = [] 9 | for q in range(60): 10 | brr = [0]*n 11 | prods = [1]*m 12 | for i in range(n): 13 | brr[i] = arr[i] + random.randint(1,k) 14 | for j in range(m): 15 | prods[j] = (prods[j]*brr[i])%primes[j] 16 | 17 | maxSum = 0 18 | 19 | for i in range(m): 20 | maxSum += prods[j] 21 | 22 | if(maxSum > max_val): 23 | max_val = maxSum 24 | best_arr = brr 25 | 26 | for i in best_arr: 27 | print i, -------------------------------------------------------------------------------- /CODECHEF/Long-April/workers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | vector cost(n); 10 | vector type(n); 11 | 12 | for(int i = 0; i < n; i++) 13 | cin >> cost[i]; 14 | 15 | for(int i = 0; i < n; i++) 16 | cin >> type[i]; 17 | 18 | int min3 = INT_MAX; 19 | int min1 = INT_MAX; 20 | int min2 = INT_MAX; 21 | 22 | for(int i = 0; i < n; i++) 23 | { 24 | 25 | if(type[i] == 3) 26 | min3 = min(min3,cost[i]); 27 | 28 | else if(type[i] == 2) 29 | min2 = min(min2,cost[i]); 30 | 31 | else if(type[i] == 1) 32 | min1 = min(min1,cost[i]); 33 | 34 | } 35 | if(min1 == INT_MAX || min2 == INT_MAX) 36 | cout << min3 << endl; 37 | else 38 | cout << min(min1+min2,min3) << endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /CODECHEF/Long-May/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Long-May/a.out -------------------------------------------------------------------------------- /CODECHEF/May-CookOFF/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/May-CookOFF/a.out -------------------------------------------------------------------------------- /CODECHEF/May-CookOFF/bestcake.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | long long int maxXorSum(long long int n, int k) 5 | { 6 | 7 | if (k == 1) 8 | return n; 9 | 10 | int res = 1; 11 | while (res <= n) 12 | { 13 | res <<= 1; 14 | } 15 | 16 | return res - 1; 17 | } 18 | 19 | 20 | int main() 21 | { 22 | int t; 23 | cin >> t; 24 | 25 | while(t--) 26 | { 27 | int n; 28 | long long int k; 29 | cin >> n >> k; 30 | 31 | cout << maxXorSum(k,n) << endl; 32 | 33 | } 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /CODECHEF/May-CookOFF/prob1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | 9 | while(t--) 10 | { 11 | int x1,x2,x3,v1,v2; 12 | cin >> x1 >> x2 >> x3 >> v1 >> v2; 13 | 14 | float t1 = abs(x3-x1)/(float)v1; 15 | float t2 = abs(x3-x2)/(float)v2; 16 | 17 | if(t1 == t2) 18 | { 19 | cout << "Draw"; 20 | } 21 | else if(t1 > t2) 22 | { 23 | cout << "Kefa"; 24 | } 25 | else 26 | { 27 | cout << "Chef"; 28 | } 29 | 30 | cout << endl; 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /CODECHEF/Mock-1/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Mock-1/a.out -------------------------------------------------------------------------------- /CODECHEF/Mock-1/alter_subarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define LL long long int 5 | 6 | bool altSign(LL a, LL b) 7 | { 8 | return ((a*b) < 0); 9 | } 10 | 11 | int main() 12 | { 13 | int t; 14 | cin >> t; 15 | while(t--) 16 | { 17 | int n; 18 | cin >> n; 19 | 20 | LL *arr = new LL[n]; 21 | 22 | for(int i = 0; i < n; i++) 23 | cin >> arr[i]; 24 | 25 | int *dp = new int[n]; 26 | 27 | for(int i = 0; i < n; i++) 28 | dp[i] = 1; 29 | 30 | for(int i = n-2; i >= 0; i--) 31 | { 32 | if(altSign(arr[i],arr[i+1])) 33 | { 34 | dp[i] = dp[i+1]+1; 35 | } 36 | } 37 | 38 | for(int i = 0; i < n; i++) 39 | cout << dp[i] << " "; 40 | 41 | cout << endl; 42 | } 43 | } -------------------------------------------------------------------------------- /CODECHEF/Mock-1/count_subs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while(t--) 9 | { 10 | int n; 11 | cin >> n; 12 | 13 | char s[100001]; 14 | scanf("%s",s); 15 | 16 | long long int cnt = 0; 17 | for(int i = 0; i < n; i++) 18 | { 19 | if(s[i] == '1') 20 | { 21 | cnt++; 22 | } 23 | } 24 | 25 | long long int ans = ((cnt*(cnt+1))/2); 26 | printf("%llu\n",ans); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /CODECHEF/Mock-1/max_weight_diff.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while(t--) 9 | { 10 | int n,k; 11 | cin >> n >> k; 12 | int *arr = new int[n]; 13 | 14 | long long int sum = 0; 15 | for(int i = 0; i < n; i++) 16 | { 17 | cin >> arr[i]; 18 | sum += arr[i]; 19 | } 20 | 21 | sort(arr,arr+n); 22 | 23 | long long int firstK = 0,lastK = 0; 24 | 25 | //This Screwed my ass 26 | k = min(k,n-k); 27 | 28 | for(int i = 0; i < k; i++) 29 | { 30 | firstK += arr[i]; 31 | } 32 | 33 | cout << sum - 2*firstK << endl; 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /CODECHEF/Mock-1/mutated_minors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while(t--) 9 | { 10 | int n,k; 11 | cin >> n >> k; 12 | 13 | int *arr = new int[n]; 14 | for(int i = 0; i < n; i++) 15 | cin >> arr[i]; 16 | 17 | int count = 0; 18 | 19 | for(int i = 0; i < n; i++) 20 | { 21 | if( (arr[i] + k) % 7 == 0 ) 22 | count++; 23 | } 24 | cout << count << endl; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /CODECHEF/Mock-2/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Mock-2/a.out -------------------------------------------------------------------------------- /CODECHEF/Sept-Long/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Sept-Long/a.out -------------------------------------------------------------------------------- /CODECHEF/Sept-Long/binary_shuffle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | int half = n/2; 10 | int x = half; 11 | 12 | for(int i = 2; i <= half; i++) 13 | cout << i << " "; 14 | 15 | cout << 1 << " "; 16 | 17 | for(int i = half + 2; i <= n; i++) 18 | cout << i << " "; 19 | cout << half + 1 << endl; 20 | 21 | cout << n << " "; 22 | for(int i = 1; i < n; i++) 23 | cout << i << " "; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /CODECHEF/Sept-Long/chef_adv.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | 9 | while(t--) 10 | { 11 | long long n,m,x,y; 12 | cin >> n >> m >> x >> y; 13 | 14 | n--; 15 | m--; 16 | 17 | if(n%x == 0 && m%y == 0) 18 | { 19 | cout << "Chefirnemo\n"; 20 | } 21 | else if(n > 0 && m > 0 && (n-1)%x == 0 && (m-1)%y == 0) 22 | { 23 | cout << "Chefirnemo\n"; 24 | } 25 | else 26 | cout << "Pofik\n"; 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /CODECHEF/Sept-Long/chef_magician.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | 9 | while(t--) 10 | { 11 | int n,x,s; 12 | cin >> n >> x >> s; 13 | 14 | for(int i = 0; i < s; i++) 15 | { 16 | int a,b; 17 | cin >> a >> b; 18 | 19 | if(a == x) 20 | { 21 | x = b; 22 | } 23 | else if(b == x) 24 | { 25 | x = a; 26 | } 27 | } 28 | 29 | cout << x << endl; 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /CODECHEF/Sept-Long/war_of_xors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | 9 | while(t--) 10 | { 11 | int n; 12 | cin >> n; 13 | 14 | vector arr(n); 15 | for(int i = 0; i < n; i++) 16 | cin >> arr[i]; 17 | 18 | 19 | 20 | 21 | 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /CODECHEF/Stacks/COMPILER.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | 9 | while(t--) 10 | { 11 | string s; 12 | cin >> s; 13 | 14 | int count = 0; 15 | 16 | int max_corr = 0; 17 | 18 | for(int i = 0; i < s.size(); i++) 19 | { 20 | if(s[i] == '<') 21 | { 22 | count++; 23 | } 24 | else if(s[i] == '>') 25 | { 26 | count--; 27 | } 28 | if(count == 0) 29 | { 30 | max_corr = i; 31 | } 32 | else if(count < 0) 33 | { 34 | break; 35 | } 36 | } 37 | cout << ((max_corr == 0)?0:max_corr+1) << endl; 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /CODECHEF/Stacks/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/CODECHEF/Stacks/a.out -------------------------------------------------------------------------------- /Clap/Primes/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Clap/Primes/a.out -------------------------------------------------------------------------------- /Clap/Primes/ip2.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 5 3 | 4 4 | 0 5 | 7 -------------------------------------------------------------------------------- /Clap/Primes/output.txt: -------------------------------------------------------------------------------- 1 | 2 3 5 7 11 2 | 2 3 5 7 3 | 4 | 2 3 5 7 11 13 17 -------------------------------------------------------------------------------- /Clap/Primes/prime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | vector primes() 6 | { 7 | vector sieve(100009,1); 8 | vector pr; 9 | 10 | sieve[0] = false; 11 | sieve[1] = false; 12 | 13 | for(int i = 2; i*i < 100009; i++) 14 | { 15 | if(sieve[i]) 16 | for(int j = i*i; j < 100009; j+= i) 17 | sieve[j] = false; 18 | } 19 | 20 | for(int i = 0; i < sieve.size(); i++) 21 | if(sieve[i]) 22 | pr.push_back(i); 23 | 24 | return pr; 25 | } 26 | int main() 27 | { 28 | 29 | ifstream in("ip2.txt"); 30 | ofstream out("output.txt"); 31 | 32 | int t; 33 | in >> t; 34 | vector prime = primes(); 35 | 36 | while(t--) 37 | { 38 | int n; 39 | in >> n; 40 | 41 | for(int i = 0; i < n; i++) 42 | out << prime[i] << " "; 43 | 44 | out << "\n"; 45 | } 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Codejam/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Codejam/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/.DS_Store -------------------------------------------------------------------------------- /Coding-Ninjas/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "0.1.0", 5 | "command": "echo", 6 | "isShellCommand": true, 7 | "args": ["Hello World"], 8 | "showOutput": "always" 9 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-1/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Assignment-1/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-1/extract_unique_characters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | char* uniqueChar(char *str){ 9 | // Write your code here 10 | unordered_map unique; 11 | char *res=new char[50000]; 12 | int k=0; 13 | for(int i=0;i>str; 29 | char *res; 30 | res=uniqueChar(str); 31 | for(int i=0;i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | int kthLargest (vector arr, int n, int k){ 7 | /* Don't write main(). 8 | * Don't read input, it is passed as function argument. 9 | * Return output and don't print it. 10 | * Taking input and printing output is handled automatically. 11 | */ 12 | sort(arr.begin(),arr.end()); 13 | return arr[n-k]; 14 | } 15 | 16 | int main() 17 | { 18 | int n; 19 | cin>>n; 20 | vector arr(n); 21 | for(int i=0;i>arr[i]; 23 | int k; 24 | cin>>k; 25 | cout< 2 | using namespace std; 3 | 4 | int binarySearch(int input[], int size, int element,int start=0) 5 | { 6 | int mid=(start+size)/2; 7 | if(start>size) 8 | { 9 | return -1; 10 | } 11 | else 12 | { 13 | if(input[mid]==element) 14 | { 15 | return mid; 16 | } 17 | else if(input[mid]element) 23 | { 24 | size=mid-1; 25 | return binarySearch(input,size,element,start); 26 | } 27 | } 28 | } 29 | 30 | int main() 31 | { 32 | int n,x; 33 | cin>>n; 34 | int arr[n]; 35 | for(int i=0;i>arr[i]; 38 | } 39 | cin>>x; 40 | cout< 2 | using namespace std; 3 | 4 | bool checkAB(char input[],char prev='\0') { 5 | // Write your code here 6 | if(input[0]=='\0') 7 | return true; 8 | else if(input[0]=='b' && prev=='\0') 9 | return false; 10 | else if(input[0]=='b' && prev=='b' && input[1]=='b') 11 | return false; 12 | else if(input[0]=='b' && prev!='b' && input[1]=='\0') 13 | return false; 14 | else if(input[0]=='b' && prev=='a' && input[1]!='b') 15 | return false; 16 | else 17 | return checkAB(input+1,input[0]); 18 | 19 | } 20 | 21 | int main() 22 | { 23 | char input[100]; 24 | scanf("%s",input); 25 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | map keyMap; 6 | 7 | void printAllPossibleCodes(string input,string output="") { 8 | /* 9 | Given the input as a string, print all its possible combinations. You do not need to return anything. 10 | */ 11 | char ch='a'; 12 | for(int i=1;i<=26;i++,ch++) 13 | keyMap[to_string(i)]=ch; 14 | 15 | if(input=="") 16 | { 17 | cout<1 && stoi(input.substr(0,2))<=26) 23 | printAllPossibleCodes(input.substr(2),output+keyMap[input.substr(0,2)]); 24 | } 25 | 26 | int main() 27 | { 28 | string input; 29 | cin>>input; 30 | printAllPossibleCodes(input); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-2-Adv_Rec/print_permutation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void printPermutations(string input,string output=""){ 7 | 8 | /* Don't write main() function. 9 | * Don't read input, it is passed as function argument. 10 | * Print output as specified in the question 11 | */ 12 | if(input=="") 13 | { 14 | cout<>input; 28 | printPermutations(input); 29 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-2-Adv_Rec/print_subset.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void printSubsetsOfArray(int input[], int size,string output="") { 5 | // Write your code here 6 | if(size==0) 7 | { 8 | cout<>n; 21 | 22 | int arr[n]; 23 | for(int i=0;i>arr[i]; 25 | 26 | printSubsetsOfArray(arr,n); 27 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-2-Adv_Rec/print_subset_sum_k.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void printSubsetSumToK(int input[], int size, int k,string output="") { 5 | // Write your code here 6 | if(size==0) 7 | { 8 | if(k==0) 9 | { 10 | cout<>n; 23 | 24 | int arr[n]; 25 | for(int i=0;i>arr[i]; 27 | 28 | int k; 29 | cin>>k; 30 | 31 | printSubsetSumToK(arr,n,k); 32 | 33 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-2-Adv_Rec/staircase.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int staircase(int n){ 5 | /* Don't write main(). 6 | * Don't read input, it is passed as function argument. 7 | * Return output and don't print it. 8 | * Taking input and printing output is handled automatically. 9 | */ 10 | if(n<0) 11 | return 0; 12 | if(n==0) 13 | return 1; 14 | else 15 | return staircase(n-1)+staircase(n-2)+staircase(n-3); 16 | 17 | } 18 | 19 | int main() 20 | { 21 | int n; 22 | cin>>n; 23 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,x; 7 | cin >> n >> x; 8 | 9 | long power = 1; 10 | 11 | for(int i = 1;i <= x;i++) 12 | { 13 | power *= n; 14 | } 15 | 16 | cout << power << endl; 17 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-4-Number-Theory/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Assignment-4-Number-Theory/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-5-Mixed/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Assignment-5-Mixed/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-5-Mixed/word_break-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | map dict; 6 | 7 | void wordbreak(string s,int n,string output) 8 | { 9 | for(int i = 1; i <= n ; i++) 10 | { 11 | string prefix = s.substr(0,i); 12 | if(dict.find(prefix)!=dict.end()) 13 | { 14 | if(i == n) 15 | { 16 | output += prefix; 17 | cout<> n; 29 | 30 | for(int i = 0; i < n ; i++) 31 | { 32 | string a; 33 | cin >> a; 34 | dict[a]++; 35 | } 36 | 37 | string s; 38 | cin >> s; 39 | wordbreak(s,s.size(),""); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-6-1-DP/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Assignment-6-1-DP/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-6-1-DP/all_ways_power.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int allWays(int x, int n,int m = 1) { 5 | /* Don't write main(). 6 | * Don't read input, it is passed as function argument. 7 | * Return output and don't print it. 8 | * Taking input and printing output is handled automatically. 9 | */ 10 | 11 | int val = (x - pow(m,n)); 12 | 13 | if(val == 0) 14 | { 15 | return 1; 16 | } 17 | 18 | if(val < 0) 19 | return 0; 20 | 21 | 22 | return allWays(val,n,m+1) + allWays(x,n,m+1); 23 | // int ans = 0; 24 | 25 | // for(int i = m; i <= x; i++) 26 | // { 27 | // ans += allWays(x-pow(i,n), n,i+1); 28 | // } 29 | // return ans; 30 | } 31 | 32 | int main() 33 | { 34 | int a,b; 35 | cin >> a >> b; 36 | 37 | cout << allWays(a,b) << endl; 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-6-1-DP/coin_tower.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int getWays(int n,int x, int y) 6 | { 7 | 8 | } 9 | 10 | string solve(int n, int x, int y) 11 | { 12 | // Write your code here . 13 | int sol = getWays(n,x,y); 14 | 15 | } 16 | 17 | int main() 18 | { 19 | int n,x,y; 20 | cin >> n >> x >> y; 21 | cout << sovle(n,x,y) << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-6-1-DP/lis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int lis(int arr[], int n) 5 | { 6 | int *dp = new int[n+1]; 7 | 8 | for(int i = 0; i <= n; i++) 9 | dp[i] = 1; 10 | 11 | dp[0] = 1; 12 | 13 | for(int i = 1; i < n; i++) 14 | { 15 | int elem = arr[i]; 16 | for(int j = i - 1; j >= 0; j--) 17 | { 18 | if(arr[j] < elem) 19 | { 20 | dp[i] = max(dp[i],dp[j]+1); 21 | } 22 | } 23 | } 24 | 25 | int mx = INT_MIN; 26 | 27 | for(int i = 0; i < n; i++) 28 | { 29 | // cout << dp[i] << " "; 30 | 31 | if(dp[i] > mx) 32 | mx = dp[i]; 33 | } 34 | 35 | return mx; 36 | } 37 | 38 | int main() 39 | { 40 | int n; 41 | cin >> n; 42 | 43 | int *arr = new int[n]; 44 | 45 | for(int i = 0; i < n; i++) 46 | cin >> arr[i]; 47 | 48 | cout << lis(arr,n) << endl; 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-6-1-DP/lis_nlogn.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void lisOptim(int *arr, int n) 6 | { 7 | vector tail; 8 | tail.push_back(arr[0]); 9 | 10 | for(int i = 1; i < n; i++) 11 | { 12 | int val = arr[i]; 13 | 14 | if(val < tail[0]) 15 | { 16 | tail[0] = val; 17 | } 18 | else if(val > tail[tail.size()-1]) 19 | { 20 | tail.push_back(val); 21 | } 22 | else 23 | { 24 | int ceilIndex = lower_bound(tail.begin(),tail.end(),val) - tail.begin(); 25 | tail[ceilIndex] = val; 26 | } 27 | } 28 | 29 | cout << tail.size() << endl; 30 | } 31 | 32 | int main() 33 | { 34 | int n; 35 | cin >> n; 36 | 37 | int *arr = new int[n]; 38 | for(int i = 0; i < n; i++) 39 | { 40 | cin >> arr[i]; 41 | } 42 | lisOptim(arr,n); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-6-Number-Theory-2/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Assignment-6-Number-Theory-2/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Assignment-6-Number-Theory-2/cubic_sqr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | 5 | // Write your code here 6 | int t; 7 | cin >> t; 8 | while(t--) 9 | { 10 | long long a,mod; 11 | string b; 12 | cin >> a >> b >> mod; 13 | int len = b.size(); 14 | long long ans = 1; 15 | while(len--) 16 | { 17 | int lsb = b[len] - '0'; 18 | if(lsb != 0) 19 | { 20 | ans = (ans * a)%mod; 21 | } 22 | if(lsb == 2) 23 | { 24 | ans = (ans * a)%mod; 25 | } 26 | a = (((a * a)%mod)*a)%mod; 27 | } 28 | cout< 2 | using namespace std; 3 | 4 | int allIndexes(int input[], int size, int x, int output[]) { 5 | /* Don't write main(). 6 | Don't read input, it is passed as function argument. 7 | Save all the indexes in the output array passed and return the size of output array. 8 | Taking input and printing output is handled automatically. 9 | */ 10 | 11 | } 12 | 13 | int main() 14 | { 15 | int arr[]={2,3,4,5,7,7,8,8,8,7,7,8}; 16 | int *brr; 17 | allIndexes(arr,12,8,brr); 18 | 19 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Basic_Recursion/array_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int sum(int input[], int n) { 5 | /* Don't write main(). 6 | Don't read input, it is passed as function argument. 7 | Return output and don't print it. 8 | Taking input and printing output is handled automatically. 9 | */ 10 | if(n==1) 11 | { 12 | return input[0]; 13 | } 14 | else 15 | { 16 | int sumC=sum(input+1,n-1); 17 | return sumC+input[0]; 18 | } 19 | 20 | } 21 | 22 | int main() 23 | { 24 | int n,x; 25 | cin>>n; 26 | int arr[n]; 27 | for(int i=0;i>arr[i]; 29 | cout< 2 | using namespace std; 3 | 4 | bool checkNumber(int input[], int size, int x) { 5 | /* Don't write main(). 6 | Don't read input, it is passed as function argument. 7 | Return output and don't print it. 8 | Taking input and printing output is handled automatically. 9 | */ 10 | if(size==0) 11 | return false; 12 | if(input[0]==x) 13 | return true; 14 | else 15 | return checkNumber(input+1,size-1,x); 16 | 17 | } 18 | 19 | int main() 20 | { 21 | int arr[]={2,4,5,6,7}; 22 | cout< 2 | using namespace std; 3 | 4 | int firstIndex(int input[], int size, int x) { 5 | /* Don't write main(). 6 | Don't read input, it is passed as function argument. 7 | Return output and don't print it. 8 | Taking input and printing output is handled automatically. 9 | */ 10 | static int count=1; 11 | if(input[0]==x && size>0) 12 | return 0; 13 | else if(size>0) 14 | { 15 | count++; 16 | return 1+firstIndex(input+1,size-1,x); 17 | } 18 | else if(size==0) 19 | { 20 | return -1*count; 21 | } 22 | 23 | } 24 | 25 | int main() 26 | { 27 | int arr[]={2,3,4,5,7,7,8}; 28 | cout< 2 | using namespace std; 3 | 4 | int lastIndex(int input[], int size, int x) { 5 | /* Don't write main(). 6 | Don't read input, it is passed as function argument. 7 | Return output and don't print it. 8 | Taking input and printing output is handled automatically. 9 | */ 10 | if(input[size-1]==x && size>0) 11 | return size-1; 12 | else if(size>0) 13 | { 14 | return lastIndex(input,size-1,x); 15 | } 16 | else 17 | { 18 | return -1; 19 | } 20 | } 21 | 22 | int main() 23 | { 24 | int arr[]={2,3,4,5,7,7,8,8,8,7,7,8}; 25 | cout< 2 | using namespace std; 3 | 4 | int count(int n){ 5 | if(n == 0){ 6 | return 0; 7 | } 8 | int smallAns = count(n / 10); 9 | return smallAns+1; 10 | } 11 | 12 | int main() 13 | { 14 | int n; 15 | cin>>n; 16 | cout< 2 | using namespace std; 3 | int power(int x, int n) { 4 | /* Don't write main(). 5 | Don't read input, it is passed as function argument. 6 | Return output and don't print it. 7 | Taking input and printing output is handled automatically. 8 | */ 9 | if(n==0) 10 | return 1; 11 | if(n==1) 12 | return x; 13 | else 14 | return x*power(x,n-1); 15 | 16 | } 17 | 18 | int main() 19 | { 20 | int n,x; 21 | cin>>x>>n; 22 | cout< 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | vector removeDuplicates(vector input){ 9 | 10 | // Write your code here 11 | unordered_map visited; 12 | vector result; 13 | for(int i=0;i>n; 29 | vector input(n); 30 | for(int i=0;i>input[i]; 32 | vector output=removeDuplicates(input); 33 | cout<<"\nOUTPUT"; 34 | for(int i=0;i 2 | using namespace std; 3 | 4 | void updateTree(int index,int value,int *BIT,int n) 5 | { 6 | for(; index <= n; index += index&(-index)) 7 | { 8 | BIT[index] += value; 9 | } 10 | } 11 | 12 | int query(int index, int *BIT) 13 | { 14 | int sum = 0; 15 | for(; index > 0; index -= index&(-index)) 16 | { 17 | sum += BIT[index]; 18 | } 19 | return sum; 20 | } 21 | 22 | int main() 23 | { 24 | int n; 25 | cin >> n; 26 | 27 | int *arr = new int[n+1](); 28 | int *BIT = new int[n+1](); 29 | for(int i = 1; i <= n; i++) 30 | { 31 | cin >> arr[i]; 32 | updateTree(i,arr[i],BIT,n); 33 | } 34 | 35 | int q; 36 | cin >> q; 37 | while(q--) 38 | { 39 | int a,b; 40 | cin >> a >> b; 41 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | //Set ith bit of a number; 7 | int n = 11; 8 | //set 2nd bit of n to 1 (from LSB) 9 | cout << (n | (1 << 2)) << endl; 10 | //Ret 1st bit of n to 0 (from LSB) 11 | cout << (n & ~(1 << 1)) << endl; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-12-Graphs-2/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-12-Graphs-2/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-13-Advanced-Graphs/CAPCITY_OP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | vector graph[100001]; 5 | vector graphT[100001]; 6 | vector> components; 7 | 8 | int main() 9 | { 10 | int n,m; 11 | cin >> n >> m; 12 | 13 | for(int i = 0; i < n; i++) 14 | { 15 | graph[i].clear(); 16 | graphT[i].clear(); 17 | } 18 | 19 | for(int i = 0; i < m; i++) 20 | { 21 | int a,b; 22 | cin >> a >> b; 23 | graph[a-1].push_back(b-1); 24 | graphT[b-1].push_back(a-1); 25 | } 26 | 27 | getSCC(n); 28 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-13-Advanced-Graphs/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-13-Advanced-Graphs/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-13-Advanced-Graphs/fill_the_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | vector graph[100001]; 5 | 6 | int main() 7 | { 8 | //code 9 | int t; 10 | cin >> t; 11 | while(t--) 12 | { 13 | int n,q; 14 | cin >> n >> q; 15 | 16 | bool init_flag = false; 17 | 18 | for(int i = 0; i < n; i++) 19 | { 20 | cout << graph[i].clear(); 21 | } 22 | 23 | for(int i = 0; i < q; i++) 24 | { 25 | int a,b,c; 26 | cin >> a >> b >> c; 27 | 28 | if(a == b && (c == 1)) 29 | { 30 | init_flag = true; 31 | } 32 | 33 | 34 | } 35 | 36 | if(init_flag) 37 | { 38 | cout << "no" << endl; 39 | } 40 | 41 | 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-14-Mixed-Problems/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-14-Mixed-Problems/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-14-Mixed-Problems/gcd_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | return 0; 7 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-16-Greedy/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-16-Greedy/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-16-Greedy/activity_selection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define LL unsigned long long int 4 | 5 | struct Activity 6 | { 7 | LL start; 8 | LL end; 9 | }; 10 | 11 | bool operator <(Activity a,Activity b) 12 | { 13 | if(a.end == b.end) 14 | { 15 | return a.start < b.start; 16 | } 17 | return a.end < b.end; 18 | } 19 | 20 | int main() 21 | { 22 | //Write your code here 23 | int n; 24 | cin >> n; 25 | 26 | Activity *act = new Activity[n]; 27 | for(int i = 0; i < n; i++) 28 | cin >> act[i].start >> act[i].end; 29 | 30 | sort(act,act+n); 31 | 32 | int cnt = 1; 33 | Activity prev = act[0]; 34 | 35 | for(int i = 1; i < n; i++) 36 | { 37 | if(prev.end <= act[i].start) 38 | { 39 | cnt++; 40 | prev = act[i]; 41 | } 42 | } 43 | 44 | cout << cnt << endl; 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-16-Greedy/himani_and_stocks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define LL unsigned long long int 5 | #define MOD 4294967296 6 | int main() 7 | { 8 | LL n,m,a,b; 9 | 10 | cin >> n >> m; 11 | cin >> a >> b; 12 | 13 | int i = 0; 14 | 15 | LL xi,xj; 16 | xi = 0; 17 | 18 | LL best = -1; 19 | LL maxProfit = 0; 20 | 21 | for(int i = 0; i < n; i++) 22 | { 23 | xj = ( ((xi%m)*a) + b)%MOD; 24 | LL currCost = xj/(1<<8); 25 | xi = xj; 26 | 27 | if(best >= 0 && best < currCost) 28 | { 29 | maxProfit += (currCost - best); 30 | } 31 | best = currCost; 32 | } 33 | 34 | cout << maxProfit << endl; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-16-Greedy/min_abs_diff.cpp: -------------------------------------------------------------------------------- 1 | // arr - input array 2 | // n - size of array 3 | #include 4 | using namespace std; 5 | 6 | int minAbsoluteDiff(int arr[], int n) { 7 | 8 | sort(arr,arr+n); 9 | int minDiff = INT_MAX; 10 | for(int i = 1; i < n; i++) 11 | { 12 | if(abs(arr[i]-arr[i-1]) < minDiff) 13 | minDiff = arr[i]-arr[i-1]; 14 | } 15 | return minDiff; 16 | } 17 | -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-16-Greedy/nikunj_and_donuts.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin >> n; 7 | 8 | int *arr = new int[n]; 9 | for(int i = 0; i < n; i++) 10 | { 11 | cin >> arr[i]; 12 | } 13 | 14 | sort(arr,arr+n,greater()); 15 | 16 | unsigned long long int miles = 0,power2 = 1; 17 | for(int i = 0; i < n; i++) 18 | { 19 | miles += (power2*arr[i]); 20 | power2 *= 2; 21 | } 22 | cout << miles << endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-17-Tries/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-17-Tries/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-18-CG/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-18-CG/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-2-Adv_rec/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-2-Adv_rec/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-2-Adv_rec/print_keypad_code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | map keyMap; 5 | void printKeypad(int n,string output="") 6 | { 7 | keyMap[0]=""; 8 | keyMap[2]="abc"; 9 | keyMap[3]="def"; 10 | keyMap[4]="ghi"; 11 | keyMap[5]="jkl"; 12 | keyMap[6]="mno"; 13 | keyMap[7]="pqrs"; 14 | keyMap[8]="tuv"; 15 | keyMap[9]="wxyz"; 16 | 17 | if(n==0) 18 | { 19 | cout<>n; 37 | printKeypad(n); 38 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-2-Adv_rec/print_subsequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print_subsequence(string input,string output) 5 | { 6 | if(input=="") 7 | { 8 | cout<>s; 22 | print_subsequence(s,""); 23 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-2-Adv_rec/replace_char.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void replaceCharacter(char input[], char c1, char c2) { 5 | /* Don't write main(). 6 | * Don't read input, it is passed as function argument. 7 | * No need to print or return the output. 8 | * Change in the given input string itself. 9 | * Taking input and printing output is handled automatically. 10 | */ 11 | if(input[0]=='\0') 12 | return; 13 | else 14 | { 15 | if(input[0]==c1) 16 | { 17 | input[0]=c2; 18 | } 19 | replaceCharacter(input+1,c1,c2); 20 | } 21 | } 22 | int main() 23 | { 24 | char arr[100]; 25 | cin>>arr; 26 | char a,b; 27 | cin>>a>>b; 28 | replaceCharacter(arr,a,b); 29 | cout< 2 | using namespace std; 3 | 4 | int subsequence(string s,string output[]) 5 | { 6 | if(s.empty()) 7 | { 8 | output[0]=""; 9 | return 1; 10 | } 11 | else 12 | { 13 | string smallString=s.substr(1); 14 | int smallOutput=subsequence(smallString,output); 15 | for(int i=0;i>s; 26 | string *output=new string[1000]; 27 | int length=subsequence(s,output); 28 | for(int i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | // Write your code here 9 | int n; 10 | cin >> n; 11 | 12 | vector sieve(n+1); 13 | 14 | sieve[0] = false; 15 | sieve[1] = false; 16 | 17 | for(int i = 2;i <= n;i++) 18 | sieve[i] = true; 19 | 20 | for(int i = 2; i <= sqrt(n); i++) 21 | { 22 | if(sieve[i]) 23 | for(int j = i*i ; j <= n ; j+=i) 24 | { 25 | sieve[j] = false; 26 | } 27 | } 28 | 29 | int count = 0; 30 | for(int i = 0; i <= n; i++) 31 | if(sieve[i]) 32 | count++; 33 | 34 | cout << count << endl; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-4-Number-Theory/gcd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int gcd(int a,int b) 6 | { 7 | //Write your code here 8 | if(a < b) 9 | return gcd(b,a); 10 | 11 | if(b == 0) 12 | return a; 13 | 14 | else 15 | return gcd(b,a%b); 16 | } 17 | 18 | int main() 19 | { 20 | int a,b; 21 | cin >>a >>b; 22 | cout< 2 | using namespace std; 3 | 4 | int modRecursive_Iterative(int a, int b, int c) 5 | { 6 | int ans = 1; 7 | while(b != 0) 8 | { 9 | // And with 1 10 | if(b&1) 11 | { 12 | ans = ((ans%c)*(a%c))%c; 13 | } 14 | a = ((a%c)*(a%c))%c; 15 | b = b/2; 16 | } 17 | return ans; 18 | } 19 | 20 | int recursiveMod(int a, int b, int c) 21 | { 22 | if(b == 0) 23 | return 1; 24 | if( b % 2 == 0) 25 | { 26 | return recursiveMod((a*a)%c,b/2,c); 27 | } 28 | else 29 | { 30 | return ((a%c)*(recursiveMod((a*a)%c,b/2,c)))%c; 31 | } 32 | } 33 | 34 | int main() 35 | { 36 | int a,b,c; 37 | cin >> a >> b >> c; 38 | cout<<"Recursive: "< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector etf_sieve(int n) 7 | { 8 | vector sieve(n+1); 9 | int i = 1; 10 | for(i = 1; i <= n ; i++) 11 | { 12 | sieve[i] = i; 13 | } 14 | for(i = 2; i <= n ; i++) 15 | { 16 | if(sieve[i] == i) 17 | { 18 | sieve[i] = sieve[i] -1; 19 | for(int j = 2*i; j <= n ; j += i) 20 | { 21 | sieve[j] = sieve[j]*(i-1)/i; 22 | } 23 | } 24 | } 25 | return sieve; 26 | } 27 | 28 | int main() 29 | { 30 | int n; 31 | cout<<"\nEnter N: "; 32 | cin >> n; 33 | vector sieve = etf_sieve(n); 34 | for(int i = 1; i <= n ; i++) 35 | cout<< i<<" "< 2 | using namespace std; 3 | 4 | void func(long long n) 5 | { 6 | // Write your code here 7 | long long etf_sieve[n+1]; 8 | long long i,j; 9 | for(i = 1; i <= n; i++) 10 | etf_sieve[i] = i; 11 | 12 | for(i = 2; i <= n ; i++) 13 | { 14 | if(etf_sieve[i] == i) 15 | { 16 | etf_sieve[i] -= 1; 17 | for(j = 2*i; j <= n ; j += i) 18 | { 19 | etf_sieve[j] = (etf_sieve[j]*(i-1))/i; 20 | } 21 | } 22 | } 23 | long long result = 0; 24 | for(i = 1; i <= n ; i++) 25 | { 26 | if(n%i == 0) 27 | { 28 | result += (etf_sieve[i]*i); 29 | } 30 | } 31 | 32 | result = (result+1)*n/2; 33 | cout<> n; 40 | func(n); 41 | } -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-6-Dynamic-Programming/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Coding-Ninjas/Lecture-6-Dynamic-Programming/a.out -------------------------------------------------------------------------------- /Coding-Ninjas/Lecture-6-Dynamic-Programming/fibonacci_dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int fibonacci(int n,int *arr) 5 | { 6 | if(n == 1 || n == 0) 7 | return 1; 8 | if(arr[n] > 0) 9 | return arr[n]; 10 | int output = fibonacci(n-1,arr) + fibonacci(n-2,arr); 11 | arr[n] = output; 12 | return output; 13 | } 14 | 15 | int main() 16 | { 17 | int n; 18 | cin >> n; 19 | int *arr = new int[n+1]; 20 | cout< 2 | using namespace std; 3 | 4 | int lis(int *input,int n) 5 | { 6 | int *output = new int[n]; 7 | output[0] = 1; 8 | for(int i = 1; i < n ; i++) 9 | { 10 | output[i] = 1; 11 | for(int j = i-1; j >= 0; j--) 12 | { 13 | if(input[j] > input[i]) 14 | continue; 15 | else 16 | { 17 | int possAns = output[j] + 1; 18 | if(possAns > output[i]) 19 | output[i] = possAns; 20 | } 21 | } 22 | } 23 | int lis_len = 0; 24 | for(int i =0 ; i < n; i++) 25 | if(lis_len < output[i]) 26 | lis_len = output[i]; 27 | 28 | return lis_len; 29 | } 30 | 31 | int main() 32 | { 33 | int n; 34 | cin >> n; 35 | int *input = new int[n]; 36 | for(int i = 0; i < n; i++) 37 | cin >> input[i]; 38 | 39 | int len = lis(input,n); 40 | cout< 2 | using namespace std; 3 | 4 | long long max_coins(long long *input,int n) 5 | { 6 | long long *output = new long long[n]; 7 | output[0] = input[0]; 8 | output[1] = max(input[0],input[1]); 9 | for(int i = 2; i < n; i++) 10 | { 11 | //Exclude ith element(then output[i] = output[i-1]) 12 | //or include ith element(then we can't include i-1th element) 13 | output[i] = max(output[i-1],output[i-2] + input[i]); 14 | } 15 | return output[n-1]; 16 | } 17 | 18 | int main() 19 | { 20 | int t; 21 | cin >> t; 22 | int t0 = 1; 23 | while(t0 <= t) 24 | { 25 | int n; 26 | cin >> n; 27 | long long *input = new long long[n]; 28 | for(int i = 0; i < n; i++) 29 | cin >> input[i]; 30 | cout<<"Case "< 2 | using namespace std; 3 | 4 | int stairCase_naive(int n) 5 | { 6 | if(n == 0) 7 | { 8 | return 1; 9 | } 10 | if(n < 0) 11 | { 12 | return 0; 13 | } 14 | return stairCase_naive(n-1)+stairCase_naive(n-2)+stairCase_naive(n-3); 15 | } 16 | 17 | long *arr; 18 | 19 | long staircase(int n) 20 | { 21 | if(n == 0) 22 | { 23 | return 1; 24 | } 25 | if(n < 0) 26 | { 27 | return 0; 28 | } 29 | if(arr[n] > 0) 30 | { 31 | return arr[n]; 32 | } 33 | long ans = staircase(n-1)+staircase(n-2)+staircase(n-3); 34 | arr[n] = ans; 35 | return ans; 36 | } 37 | int main() 38 | { 39 | int n; 40 | cin >> n; 41 | arr = new long[n+1]; 42 | if(n <= 2) 43 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int arr[10]; 6 | int *p; 7 | 8 | p=arr; 9 | 10 | arr[0]=5; 11 | arr[1]=10; 12 | 13 | cout<<"Both Points to same address"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,m; 7 | cin >> n >> m; 8 | 9 | ofstream file; 10 | file.open("input.txt",ios::app); 11 | 12 | set> edges; 13 | 14 | for(int i = 0; i < n; i++) 15 | { 16 | for(int j = i+1; j < n; j++) 17 | { 18 | edges.insert(make_pair(i,j)); 19 | } 20 | } 21 | 22 | set> edgeSet; 23 | edgeSet.insert(*(edges.begin())); 24 | 25 | m = min(m,n*(n-1)/2); 26 | 27 | while(edgeSet.size() < m) 28 | { 29 | int random = rand()%(edges.size()); 30 | pair val = *next(edges.begin(),random); 31 | edgeSet.insert(val); 32 | } 33 | file << n << " " << m << endl; 34 | for(auto it : edgeSet) 35 | { 36 | cout << it.first << " " << it.second << endl; 37 | file << it.first << " " << it.second << endl; 38 | } 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /DAA-2/output1.txt: -------------------------------------------------------------------------------- 1 | 9 37 2 | 6 35 3 | 40 112 4 | 20 74 5 | 55 142 6 | 110 700 7 | 200 720 8 | 4100 8502 9 | 2200 7614 10 | 9998 36618 11 | 5001 35000 12 | 100002 700000 13 | 20005 140000 14 | 16000 70092 15 | 14000 70000 16 | 8000 35054 17 | 1200 7000 18 | -------------------------------------------------------------------------------- /DAA-2/output2.txt: -------------------------------------------------------------------------------- 1 | 9 40 2 | 6 14 3 | 40 244 4 | 20 113 5 | 55 351 6 | 110 190 7 | 200 1225 8 | 4100 28410 9 | 2200 14106 10 | 9998 61720 11 | 5001 5009 12 | 100002 100018 13 | 20005 20044 14 | 16000 76117 15 | 14000 50053 16 | 8000 38041 17 | 1200 2868 18 | -------------------------------------------------------------------------------- /DAA-2/plotter.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | plot1 = [] 4 | plot2 = [] 5 | with open("output1.txt") as f: 6 | for line in f: 7 | plot1 += [list(map(int,line.split()))] 8 | 9 | with open("output2.txt") as f: 10 | for line in f: 11 | plot2 += [list(map(int,line.split()))] 12 | 13 | plot1.sort(key = lambda x : x[0]) 14 | plot2.sort(key = lambda x : x[0]) 15 | 16 | x_val = [x[0] for x in plot1] 17 | y1 = [x[1] for x in plot1] 18 | y2 = [x[1] for x in plot2] 19 | 20 | print("X",x_val) 21 | print("DFS",y1) 22 | print("DSU",y2) 23 | 24 | plt.title('Connected Components Using DFS & Union-Find') 25 | plt.xlabel('V + E') 26 | plt.ylabel('Number of Steps T(V+E)') 27 | plt.plot(x_val,y1) 28 | plt.plot(x_val,y2) 29 | 30 | plt.legend(['DFS = 1', 'Union-Find = 2'], loc='upper left') 31 | 32 | plt.show() -------------------------------------------------------------------------------- /Data-Structures/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | 5 | { 6 | "name": "(gdb) Launch", 7 | "type": "cppdbg", 8 | "request": "launch", 9 | "program": "enter program name, for example ${workspaceRoot}/a.out", 10 | "args": [], 11 | "stopAtEntry": false, 12 | "cwd": "${workspaceRoot}", 13 | "environment": [], 14 | "externalConsole": true, 15 | "MIMode": "gdb", 16 | "setupCommands": [{ 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | }] 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /Data-Structures/BTrees/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/BTrees/a.out -------------------------------------------------------------------------------- /Data-Structures/Binary-Trees/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Binary-Trees/a.out -------------------------------------------------------------------------------- /Data-Structures/Binary_Search_Trees/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Binary_Search_Trees/a.out -------------------------------------------------------------------------------- /Data-Structures/Graphs/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Graphs/a.out -------------------------------------------------------------------------------- /Data-Structures/Graphs/graph_adj_list.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int V,E; 7 | cin >> V >> E; 8 | int matrix[V][V]; 9 | 10 | vector *graph = new vector[V]; 11 | for(int i = 0; i < E; i++) 12 | { 13 | int a,b; 14 | cin >> a >> b; 15 | 16 | graph[b].push_back(a); 17 | graph[a].push_back(b); 18 | } 19 | cout << "\nGRaph is : \n"; 20 | for(int i = 0; i < V; i++) 21 | { 22 | cout << i << " : "; 23 | for(int j = 0; j < graph[i].size(); j++) 24 | { 25 | cout << graph[i][j] << " "; 26 | } 27 | cout << endl; 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Data-Structures/Graphs/iter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | vector> graph; 7 | vector g; 8 | 9 | g.push_back(1); 10 | g.push_back(2); 11 | g.push_back(13); 12 | 13 | graph.push_back(g); 14 | g.clear(); 15 | 16 | g.push_back(13); 17 | graph.push_back(g); 18 | 19 | 20 | vector>::iterator it; 21 | vector::iterator it1; 22 | 23 | for(it = graph.begin(); it != graph.end(); it++) 24 | { 25 | for(it1 = (*it).begin(); it1 != (*it).end(); it1++) 26 | { 27 | cout << *it1 << " "; 28 | } 29 | cout << endl; 30 | } 31 | 32 | for(auto it2 : graph) 33 | { 34 | for(auto it3 : it2) 35 | { 36 | cout << it3 << " "; 37 | } 38 | cout << endl; 39 | } 40 | 41 | 42 | 43 | } -------------------------------------------------------------------------------- /Data-Structures/Heaps/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Heaps/a.out -------------------------------------------------------------------------------- /Data-Structures/Linked-Lists/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Linked-Lists/a.out -------------------------------------------------------------------------------- /Data-Structures/Test.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Test.class -------------------------------------------------------------------------------- /Data-Structures/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Tree 5 | { 6 | int data; 7 | Tree left,right; 8 | 9 | 10 | Tree(int data){ 11 | this.data=data; 12 | left=right=null; 13 | } 14 | 15 | 16 | } 17 | class Test 18 | { 19 | public static void inOrder(Tree node) 20 | { 21 | if(node==null) 22 | return; 23 | inOrder(node.left); 24 | System.out.println(node.data); 25 | inOrder(node.right); 26 | } 27 | 28 | public static void main(String args[]) 29 | { 30 | Tree node=new Tree(7); 31 | node.left=new Tree(5); 32 | node.right=new Tree(4); 33 | inOrder(node); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Data-Structures/Tree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Tree.class -------------------------------------------------------------------------------- /Data-Structures/Trees/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/Trees/a.out -------------------------------------------------------------------------------- /Data-Structures/Trees/topview.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Node 5 | { 6 | int data; 7 | struct Node* left, * right; 8 | }; 9 | 10 | void topView(node * root) 11 | { 12 | if(root==NULL) 13 | return; 14 | 15 | unordered_map m; 16 | queue> que; 17 | 18 | que.push(make_pair(root,0)); 19 | 20 | while(!que.empty()) 21 | { 22 | pair p=que.front(); 23 | node* n=p.first; 24 | int val=p.second; 25 | que.pop(); 26 | 27 | if(m.find(val)==m.end()) 28 | { 29 | m[val]=n->data; 30 | cout<data<<" "; 31 | } 32 | if(n->left!=NULL) 33 | que.push(make_pair(n->left,val-1)); 34 | if(n->right!=NULL) 35 | que.push(make_pair(n->right,val+1)); 36 | } 37 | 38 | } 39 | 40 | int main() 41 | { 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Data-Structures/Trees/tree.cp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | -------------------------------------------------------------------------------- /Data-Structures/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Data-Structures/a.out -------------------------------------------------------------------------------- /Data-Structures/dynamic_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | long n,q; 12 | cin>>n>>q; 13 | 14 | vector> seqList(n); 15 | 16 | long i,x,y,z; 17 | long lastAnswer=0; 18 | for(i=0;i>x>>y>>z; 21 | 22 | long index=(y^lastAnswer)%n; 23 | if(x==1) 24 | { 25 | seqList[index].push_back(z); 26 | } 27 | else 28 | { 29 | long j_index=z%(seqList[index].size()); 30 | lastAnswer=seqList[index][j_index]; 31 | cout< 2 | 3 | using namespace std; 4 | 5 | string feeOrUpfront(int n, int k, int x, int d, vector p) { 6 | // Complete this function 7 | float i,j,sum=0; 8 | vector interests(n); 9 | for(int i=0;i> q; 23 | for(int a0 = 0; a0 < q; a0++){ 24 | int n; 25 | int k; 26 | int x; 27 | int d; 28 | cin >> n >> k >> x >> d; 29 | vector p(n); 30 | for(int p_i = 0; p_i < n; p_i++){ 31 | cin >> p[p_i]; 32 | } 33 | string result = feeOrUpfront(n, k, x, d, p); 34 | cout << result << endl; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Goldman-Sachs/currencies.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | def currencies(n, x, s, f, m, A): 6 | maxVals=[] 7 | for i in range(n): 8 | maxVals+=[(i,max(A[i]),A[i].index(max(A[i])))] 9 | print(maxVals) 10 | for j in range(n): 11 | for i in range(k): 12 | 13 | 14 | if __name__ == "__main__": 15 | n = int(raw_input().strip()) 16 | x, s, f, m = raw_input().strip().split(' ') 17 | x, s, f, m = [int(x), int(s), int(f), int(m)] 18 | A = [] 19 | for A_i in xrange(n): 20 | A_temp = map(float,raw_input().strip().split(' ')) 21 | A.append(A_temp) 22 | currencies(n,x,s,f,m,A) 23 | -------------------------------------------------------------------------------- /Goldman-Sachs/v: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Goldman-Sachs/v -------------------------------------------------------------------------------- /Graph.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Graph.class -------------------------------------------------------------------------------- /Hash-Combat/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Hash-Combat/a.out -------------------------------------------------------------------------------- /Hash-Combat/p2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | return 0; 7 | } -------------------------------------------------------------------------------- /Hash-Combat/p3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | return 0; 7 | } -------------------------------------------------------------------------------- /HourRank23/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/HourRank23/a.out -------------------------------------------------------------------------------- /HourRank23/ques1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int howManyGames(int p, int d, int m, int s) { 6 | // Return the number of games you can buy 7 | int answer=0; 8 | if(s>=p) 9 | { 10 | while(s >=0 && p >=m) 11 | { 12 | s -= p; 13 | p -= d; 14 | answer++; 15 | } 16 | while(s >= m) 17 | { 18 | s -= m; 19 | answer++; 20 | } 21 | return answer; 22 | } 23 | else return 0; 24 | } 25 | 26 | int main() { 27 | int p; 28 | int d; 29 | int m; 30 | int s; 31 | cin >> p >> d >> m >> s; 32 | int answer = howManyGames(p, d, m, s); 33 | cout << answer << endl; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Quest-Python/file.py: -------------------------------------------------------------------------------- 1 | #coding=utf8 2 | with open("test.txt",'w',encoding='utf-8') as f: 3 | f.write("my first line\n") 4 | f.write("This file\n\n") 5 | f.write("contains three lines\n") 6 | f.write("Cooperate") 7 | 8 | with open("test.txt",'r',encoding='utf-8') as f: 9 | for line in f: 10 | print(line) -------------------------------------------------------------------------------- /Quest-Python/read_write.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | 3 | class Stud: 4 | def __init__(self,n,name,m): 5 | self.__num = n 6 | self.__name = name 7 | self.__marks = m 8 | 9 | def __str__(self): 10 | return str(self.__num) + " " + self.__name + " " + str(self.__marks) 11 | 12 | data = list() 13 | 14 | for i in range(2): 15 | num = int(input("Enter Number: ")) 16 | name = input("Enter Name: ") 17 | marks = int(input("Enter Marks: ")) 18 | c = Stud(num,name,marks) 19 | 20 | data.append(c) 21 | 22 | fh = open("stud.pickle","wb") 23 | 24 | for i in data: 25 | pickle.dump(i,fh) 26 | 27 | fh.close() 28 | 29 | fg = open("stud.pickle","rb") 30 | data2 = list() 31 | 32 | while(True): 33 | try: 34 | c = pickle.load(fg) 35 | data2.append(c) 36 | except EOFError: 37 | break 38 | 39 | print(data2) -------------------------------------------------------------------------------- /Quest-Python/stud.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Quest-Python/stud.pickle -------------------------------------------------------------------------------- /Quest-Python/test.txt: -------------------------------------------------------------------------------- 1 | my first line 2 | This file 3 | 4 | contains three lines 5 | Cooperate -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Competitive-Coding 2 | Repository With Solutions to Hackerrank Challenges and Competitive Coding Problems 3 | -------------------------------------------------------------------------------- /SOPC-18/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/SOPC-18/a.out -------------------------------------------------------------------------------- /SOPC-18/superman.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | double calcSec(int b,int s,double p) 5 | { 6 | int sec = 0; 7 | double temp = b/2.0; 8 | double str = temp + p*(s-temp); 9 | if(str > b) 10 | return 0; 11 | else 12 | { 13 | while(str <= b) 14 | { 15 | sec++; 16 | str += (p*(s-str)); 17 | } 18 | } 19 | return sec; 20 | 21 | } 22 | 23 | int main() 24 | { 25 | int t; 26 | cin >> t; 27 | while(t--) 28 | { 29 | int b,s; 30 | double p; 31 | cin >> s >> b; 32 | cin >> p; 33 | cout< 2 | #define LL long long int 3 | using namespace std; 4 | 5 | int minimumLoss(vector price) { 6 | // Complete this function 7 | set freq; 8 | freq.insert(price[0]); 9 | LL minDiff = INT_MAX; 10 | for(int i = 1; i < price.size(); i++) 11 | { 12 | if(freq.upper_bound(price[i]) != freq.end()) 13 | { 14 | minDiff = min(minDiff,*freq.upper_bound(price[i]) - price[i]); 15 | } 16 | freq.insert(price[i]); 17 | } 18 | 19 | return minDiff; 20 | } 21 | 22 | int main() { 23 | int n; 24 | cin >> n; 25 | vector price(n); 26 | for(int price_i = 0; price_i < n; price_i++){ 27 | cin >> price[price_i]; 28 | } 29 | LL result = minimumLoss(price); 30 | cout << result << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Searching/minimum_loss_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LL long long int 3 | using namespace std; 4 | 5 | int minimumLoss(vector price) { 6 | // Complete this function 7 | vector> values; 8 | for(int i = 0; i < price.size(); i++) 9 | values.push_back(make_pair(price[i],i)); 10 | sort(values.begin(),values.end()); 11 | LL minDiff = INT_MAX; 12 | for(int i = 0; i < values.size()-1; i++) 13 | { 14 | if(values[i+1].first-values[i].first < minDiff && values[i+1].second < values[i].second) 15 | { 16 | minDiff = values[i+1].first-values[i].first; 17 | } 18 | } 19 | return minDiff; 20 | } 21 | 22 | int main() { 23 | int n; 24 | cin >> n; 25 | vector price(n); 26 | for(int price_i = 0; price_i < n; price_i++){ 27 | cin >> price[price_i]; 28 | } 29 | LL result = minimumLoss(price); 30 | cout << result << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Searching/pairs_sol1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LL long long int 3 | using namespace std; 4 | 5 | LL pairs(int k, vector arr) 6 | { 7 | // Complete this function 8 | unordered_set freq; 9 | for(int i = 0; i < arr.size(); i++) 10 | freq.insert(arr[i]); 11 | 12 | LL count = 0; 13 | unordered_set:: iterator it; 14 | for(it = freq.begin(); it != freq.end();) 15 | { 16 | if(freq.find(*it-k) != freq.end()) 17 | { 18 | count++; 19 | } 20 | if(freq.find(*it+k) != freq.end()) 21 | { 22 | count++; 23 | } 24 | freq.erase(*it); 25 | it = freq.begin(); 26 | } 27 | return count; 28 | 29 | } 30 | 31 | int main() { 32 | int n; 33 | int k; 34 | cin >> n >> k; 35 | vector arr(n); 36 | for(int arr_i = 0; arr_i < n; arr_i++){ 37 | cin >> arr[arr_i]; 38 | } 39 | int result = pairs(k, arr); 40 | cout << result << endl; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Solutions.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Solutions.zip -------------------------------------------------------------------------------- /TRIUMPH/Assignment-0-Patterns/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Assignment-0-Patterns/a.out -------------------------------------------------------------------------------- /TRIUMPH/Assignment-0-Patterns/arrow_pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | 10 | int space = 0; 11 | int count = 1; 12 | 13 | for(int i = 1; i <= n; i++) 14 | { 15 | for(int j = 0; j < space; j++) 16 | { 17 | cout << " "; 18 | } 19 | 20 | for(int k = 1; k <= count; k++) 21 | { 22 | cout << "* "; 23 | } 24 | 25 | if(i <= n/2) 26 | { 27 | count++; 28 | space++; 29 | } 30 | else 31 | { 32 | count--; 33 | space--; 34 | } 35 | 36 | cout << endl; 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-0-Patterns/matrix_order_pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void printPattern(int n) 6 | { 7 | for(int i = 1; i <= n; i += 2) 8 | { 9 | for(int j = 1; j <= n; j++) 10 | { 11 | cout << ((i-1)*n)+j << " "; 12 | } 13 | cout << endl; 14 | } 15 | 16 | int k; 17 | 18 | if(n % 2 == 0) 19 | { 20 | k = n; 21 | } 22 | else 23 | { 24 | k = n-1; 25 | } 26 | 27 | for(int i = k; i > 0; i -= 2) 28 | { 29 | for(int j = 1; j <= n; j++) 30 | { 31 | cout << ((i-1)*n)+j << " "; 32 | } 33 | cout << endl; 34 | } 35 | } 36 | 37 | int main() 38 | { 39 | int n; 40 | cin >> n; 41 | printPattern(n); 42 | return 0; 43 | } -------------------------------------------------------------------------------- /TRIUMPH/Assignment-0-Patterns/number_pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | int space = n-1; 10 | 11 | int num = 1; 12 | 13 | for(int i = 1; i <= n; i++) 14 | { 15 | for(int j = 1; j <= space; j++) 16 | { 17 | cout << " "; 18 | } 19 | 20 | for(int j = num; j <= 2*num - 1; j++ ) 21 | { 22 | 23 | cout << j ; 24 | } 25 | num++; 26 | space--; 27 | 28 | cout << endl; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-0-Patterns/number_pattern_5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | int fillPos = 1; 10 | 11 | for(int i = 1; i <= n; i++) 12 | { 13 | for(int j = 1; j <= 2*n; j++) 14 | { 15 | if(j <= fillPos) 16 | { 17 | cout << j; 18 | } 19 | 20 | else if( j >= 2*n - fillPos + 1 ) 21 | { 22 | cout << (2*n-j)+1; 23 | } 24 | 25 | else 26 | { 27 | cout << " "; 28 | } 29 | } 30 | cout << endl; 31 | fillPos++; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-0-Patterns/number_pattern_grid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void printPattern(int n) 6 | { 7 | int print = n; 8 | int range = n; 9 | 10 | for(int i = 1; i <= 2*n - 1; i++) 11 | { 12 | for(int j = 1; j <= n; j++) 13 | { 14 | if(j >= range) 15 | { 16 | cout << n-j << " "; 17 | } 18 | else 19 | { 20 | cout << n << " "; 21 | } 22 | } 23 | for(int j = n+1; j <= 2*n-1; j++) 24 | { 25 | if(j <= 2*n-range) 26 | { 27 | cout << 2*n-1-j << " "; 28 | } 29 | else 30 | { 31 | cout << n << " "; 32 | } 33 | } 34 | range--; 35 | cout << endl; 36 | } 37 | 38 | } 39 | 40 | int main() 41 | { 42 | int n; 43 | cin >> n; 44 | printPattern(n); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /TRIUMPH/Assignment-0-Patterns/triangle_patterns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | int space = n-1; 10 | 11 | int num = 1; 12 | 13 | for(int i = 1; i <= n; i++) 14 | { 15 | for(int j = 1; j <= space; j++) 16 | { 17 | cout << " "; 18 | } 19 | 20 | for(int j = num; j <= 2*num - 1; j++ ) 21 | { 22 | 23 | cout << j ; 24 | } 25 | 26 | for(int j = 2*num - 2; j >= num; j--) 27 | { 28 | cout << j; 29 | } 30 | 31 | num++; 32 | space--; 33 | 34 | cout << endl; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-2-Arrays-Strings/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Assignment-2-Arrays-Strings/a.out -------------------------------------------------------------------------------- /TRIUMPH/Assignment-2-Arrays-Strings/leaders_in_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void Leaders(int* arr,int len) 5 | { 6 | /* Don't write main(). 7 | * Don't read input, it is passed as function argument. 8 | * Print your output exactly in the same format as shown. 9 | * Don't print any extra line. 10 | */ 11 | vector st; 12 | 13 | int max = arr[len-1]; 14 | 15 | st.push_back(max); 16 | 17 | for(int i = len-2; i >= 0; i--) 18 | { 19 | if(arr[i] >= max) 20 | { 21 | max = arr[i]; 22 | st.push_back(max); 23 | } 24 | } 25 | for(int i = st.size()-1; i >= 0; i--) 26 | cout << st[i] << " "; 27 | 28 | } 29 | 30 | 31 | int main() 32 | { 33 | int n; 34 | cin >> n; 35 | 36 | int *arr = new int[n]; 37 | for(int i = 0; i < n; i++) 38 | { 39 | cin >> arr[i]; 40 | } 41 | 42 | Leaders(arr,n); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /TRIUMPH/Assignment-2-Arrays-Strings/reverse_words.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void reverseStringWordWise(char input[]) { 5 | // Write your code here 6 | int len = strlen(input); 7 | 8 | for(int i = 0; i < len/2; i++) 9 | { 10 | swap(input[i],input[len-i-1]); 11 | } 12 | 13 | int start = 0; 14 | int i; 15 | 16 | for(i = 0; i < len; i++) 17 | { 18 | if(input[i] == ' ') 19 | { 20 | for(int j = 0; j < (i-start)/2; j++) 21 | { 22 | swap(input[start+j],input[i-j-1]); 23 | } 24 | start = i+1; 25 | } 26 | } 27 | for(int j = 0; j < (i-start)/2; j++) 28 | { 29 | swap(input[start+j],input[i-j-1]); 30 | } 31 | } 32 | 33 | int main() 34 | { 35 | char input[1000]; 36 | fgets(input,100,stdin); 37 | 38 | reverseStringWordWise(input); 39 | for(int i = 0; input[i] != '\0'; i++) 40 | cout << input[i]; 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /TRIUMPH/Assignment-2-Arrays-Strings/sort_012_DNF.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void sort012DNF(int *arr, int n) 5 | { 6 | int low = 0; 7 | int high = n-1; 8 | int mid = 0; 9 | 10 | while(mid <= high) 11 | { 12 | switch(arr[mid]) 13 | { 14 | case 0: 15 | swap(arr[mid],arr[low]); 16 | low++; 17 | mid++; 18 | break; 19 | case 1: 20 | mid++; 21 | break; 22 | case 2: 23 | swap(arr[mid],arr[high]); 24 | high--; 25 | break; 26 | } 27 | } 28 | } 29 | 30 | int main() 31 | { 32 | int n; 33 | cin >> n; 34 | 35 | int *arr = new int[n]; 36 | 37 | for(int i = 0; i < n; i++) 38 | cin >> arr[i]; 39 | 40 | sort012DNF(arr,n); 41 | for(int i = 0; i < n; i++) 42 | cout << arr[i] << " "; 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /TRIUMPH/Assignment-2-Arrays-Strings/wave_print.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void wavePrint(int input[][1000], int row, int col){ 5 | /* Don't write main(). 6 | * Don't read input, it is passed as function argument. 7 | * Print output and don't return it. 8 | * Taking input is handled automatically. 9 | */ 10 | for(int i = 0; i < col; i++) 11 | { 12 | if(i % 2 == 0) 13 | { 14 | for(int j = 0; j < row; j++) 15 | cout << input[j][i] << " "; 16 | } 17 | else 18 | { 19 | for(int j = row-1; j >= 0; j--) 20 | cout << input[j][i] << " "; 21 | } 22 | } 23 | } 24 | 25 | int main() 26 | { 27 | int mat[][1000] = {{1,2,3},{4,5,6},{7,8,9}}; 28 | wavePrint(mat,3,3); 29 | } 30 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-3-HashMaps/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Assignment-3-HashMaps/a.out -------------------------------------------------------------------------------- /TRIUMPH/Assignment-3-HashMaps/highest_freq.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int highestFrequency(int *input, int n) 5 | { 6 | unordered_map freqMap; 7 | int max_count = 1; 8 | int max_num = input[0]; 9 | for(int i = 0; i < n; i++) 10 | { 11 | freqMap[input[i]]++; 12 | if(freqMap[input[i]] > max_count) 13 | { 14 | max_count = freqMap[input[i]]; 15 | max_num = input[i]; 16 | } 17 | } 18 | return max_num; 19 | } 20 | 21 | int main() 22 | { 23 | int n; 24 | cin >> n; 25 | 26 | int *arr = new int[n]; 27 | for(int i = 0; i < n; i++) 28 | cin >> arr[i]; 29 | 30 | cout << highestFrequency(arr,n) << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-3-HashMaps/longest_0_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int max(int arr[], int n) 6 | { 7 | map diffMap; 8 | 9 | int count0 = 0; 10 | int count1 = 0; 11 | 12 | diffMap[0] = -1; 13 | 14 | int res = 0; 15 | for(int i = 0; i < n; i++) 16 | { 17 | 18 | if(arr[i] == 0) 19 | count0++; 20 | else 21 | count1++; 22 | 23 | if( diffMap.find(count1 - count0) != diffMap.end() ) 24 | { 25 | res = max(res,i - diffMap[count1-count0]); 26 | } 27 | else 28 | { 29 | diffMap[count1-count0] = i; 30 | } 31 | 32 | } 33 | } 34 | 35 | int main() 36 | { 37 | int n; 38 | cin >> n; 39 | 40 | int *arr = new int[n]; 41 | for(int i = 0; i < n; i++) 42 | cin >> arr[i]; 43 | 44 | cout << max(arr,n) << endl; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-3-HashMaps/make_anagrams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int makeAnagram(char str1[], char str2[]) 5 | { 6 | map cnt1,cnt2; 7 | 8 | for(int i = 0; str1[i] != '\0'; i++) 9 | { 10 | cnt1[str1[i]]++; 11 | } 12 | for(int i = 0; str2[i] != '\0'; i++) 13 | { 14 | cnt2[str2[i]]++; 15 | } 16 | 17 | int diff = 0; 18 | 19 | for(char ch = 'a'; ch <= 'z'; ch++) 20 | { 21 | diff += abs(cnt1[ch] - cnt2[ch]); 22 | } 23 | return diff; 24 | } 25 | 26 | int main() 27 | { 28 | char str1[100],str2[100]; 29 | cin >> str1; 30 | cin >> str2; 31 | cout << makeAnagram(str1,str2); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /TRIUMPH/Assignment-3-HashMaps/min_repeat_dist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int minDistance(int arr[],int n) 5 | { 6 | unordered_map freqMap; 7 | int min_rep = INT_MAX; 8 | 9 | for(int i = 0; i < n; i++) 10 | { 11 | if(freqMap[arr[i]] == 0) 12 | { 13 | freqMap[arr[i]] = i+1; 14 | } 15 | else 16 | { 17 | min_rep = min(min_rep,(i - freqMap[arr[i]] + 1) ); 18 | freqMap[arr[i]] = i+1; 19 | } 20 | } 21 | 22 | if(min_rep == INT_MAX) 23 | return -1; 24 | else return min_rep; 25 | } 26 | 27 | int main() 28 | { 29 | int n; 30 | cin >> n; 31 | 32 | int *arr = new int[n]; 33 | for(int i = 0; i < n; i++) 34 | cin >> arr[i]; 35 | 36 | cout << minDistance(arr,n) << endl; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/delete_recursive.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | * Following is the Node class that is already written. 3 | 4 | class Node{ 5 | public: 6 | int data; 7 | Node *next; 8 | Node(int data){ 9 | this -> data = data; 10 | this -> next = NULL; 11 | } 12 | }; 13 | 14 | *********/ 15 | 16 | Node* deleteNodeRec(Node *head, int i) { 17 | /* Don't write main(). 18 | * Don't read input, it is passed as function argument. 19 | * Return output and don't print it. 20 | * Taking input is handled automatically. 21 | */ 22 | if(head == NULL) 23 | { 24 | return head; 25 | } 26 | if(i == 0) 27 | { 28 | Node *temp = head; 29 | head = head->next; 30 | free(temp); 31 | return head; 32 | } 33 | head->next = deleteNodeRec(head->next,i-1); 34 | return head; 35 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/divide_alternating.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-10-LL-1/divide_alternating.cpp -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/insert_recursive.cpp: -------------------------------------------------------------------------------- 1 | //head is head of linked list,i is the index, data is data of your node 2 | // Following is the node structure 3 | /************** 4 | class Node{ 5 | public: 6 | int data; 7 | Node *next; 8 | Node(int data){ 9 | this -> data = data; 10 | this -> next = NULL; 11 | } 12 | }; 13 | ***************/ 14 | 15 | Node* insertNodeRec(Node *head, int i, int data) { 16 | /* Don't write main(). 17 | * Don't read input, it is passed as function argument. 18 | * Return output and don't print it. 19 | * Taking input is handled automatically. 20 | */ 21 | if(head == NULL) 22 | { 23 | return head; 24 | } 25 | if(i == 0) 26 | { 27 | //Insert at head of this linked list 28 | Node *node = new Node(data); 29 | node->next = head; 30 | head = node; 31 | return head; 32 | } 33 | head->next = insertNodeRec(head->next,i-1,data); 34 | return head; 35 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/length_iter.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | * Following is the Node class that is already written. 3 | 4 | class Node{ 5 | public: 6 | int data; 7 | Node *next; 8 | Node(int data){ 9 | this -> data = data; 10 | this -> next = NULL; 11 | } 12 | }; 13 | 14 | *********/ 15 | 16 | int length(Node *head) { 17 | /* Don't write main(). 18 | * Don't read input, it is passed as function argument. 19 | * Return output and don't print it. 20 | * Taking input is handled automatically. 21 | */ 22 | int cnt = 0; 23 | Node *temp = head; 24 | while(temp != NULL) 25 | { 26 | temp = temp->next; 27 | cnt++; 28 | } 29 | return cnt; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/move_last_first.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | /************* 4 | Following is the Node structure already written. 5 | 6 | template 7 | class Node { 8 | public: 9 | T data; 10 | Node* next; 11 | 12 | Node(T data) { 13 | next = NULL; 14 | this->data = data; 15 | } 16 | 17 | ~Node() { 18 | if (next != NULL) { 19 | delete next; 20 | } 21 | } 22 | }; 23 | 24 | *************/ 25 | 26 | //1 2 3 4 5 6 -1 27 | //6 1 2 3 4 5 -1 28 | 29 | Node* moveToFront(Node *head_ref) { 30 | // Write your code here 31 | Node *temp = head_ref; 32 | 33 | while(temp->next != NULL && temp->next->next != NULL) 34 | { 35 | temp = temp->next; 36 | } 37 | 38 | Node *last = temp->next; 39 | temp->next = NULL; 40 | last->next = head_ref; 41 | head_ref = last; 42 | return head_ref; 43 | } 44 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/print_ith.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | * Following is the Node class that is already written. 3 | 4 | class Node{ 5 | public: 6 | int data; 7 | Node *next; 8 | Node(int data){ 9 | this -> data = data; 10 | this -> next = NULL; 11 | } 12 | }; 13 | 14 | *********/ 15 | 16 | void printIthNode(Node *head, int i) { 17 | /* Don't write main(). 18 | * Don't read input, it is passed as function argument. 19 | * Print output and don't return it. 20 | * Taking input is handled automatically. 21 | */ 22 | int cnt = 0; 23 | Node *temp = head; 24 | 25 | while(temp != NULL) 26 | { 27 | if(cnt == i) 28 | { 29 | cout << temp->data << endl; 30 | } 31 | cnt++; 32 | temp = temp->next; 33 | } 34 | 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/reverse_k_group.cpp: -------------------------------------------------------------------------------- 1 | //head is the head of the linked list, n is number of elements to be reversed 2 | // Following is the node structure 3 | /************** 4 | class node{ 5 | public: 6 | int data; 7 | node * next; 8 | node(int data){ 9 | this->data=data; 10 | this->next=NULL; 11 | } 12 | }; 13 | ***************/ 14 | 15 | node* kReverse(node*head,int n) 16 | { 17 | if(head == NULL) 18 | { 19 | return head; 20 | } 21 | 22 | node *curr = head; 23 | node *prev = NULL; 24 | node *next; 25 | 26 | int k = n; 27 | 28 | while(curr != NULL && k != 0) 29 | { 30 | next = curr->next; 31 | curr->next = prev; 32 | prev = curr; 33 | curr = next; 34 | k--; 35 | } 36 | 37 | head->next = kReverse(next,n); 38 | return prev; 39 | } 40 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/skipMdeleteN.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class node{ 5 | public: 6 | int data; 7 | node * next; 8 | node(int data){ 9 | this->data=data; 10 | this->next=NULL; 11 | } 12 | }; 13 | 14 | node* skipMdeleteN(node *head, int M, int N) { 15 | // Write your code here 16 | node *temp = head; 17 | 18 | while(temp) 19 | { 20 | int k = 0; 21 | while(temp && k < M-1) 22 | { 23 | temp = temp->next; 24 | k++; 25 | } 26 | node *tail = temp; 27 | 28 | if(temp != NULL) 29 | temp = temp->next; 30 | 31 | while(temp && k < M + N -1) 32 | { 33 | node *next = temp; 34 | temp = temp->next; 35 | free(next); 36 | k++; 37 | } 38 | if(tail != NULL) 39 | tail->next = temp; 40 | } 41 | 42 | return head; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-10-LL-1/swap_nodes.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-10-LL-1/swap_nodes.cpp -------------------------------------------------------------------------------- /TRIUMPH/Lecture-11-LL-2/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-11-LL-2/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-11-LL-2/midpoint_ll.cpp: -------------------------------------------------------------------------------- 1 | // Following is the node structure 2 | /************** 3 | class node{ 4 | public: 5 | int data; 6 | node * next; 7 | node(int data){ 8 | this->data=data; 9 | this->next=NULL; 10 | } 11 | }; 12 | ***************/ 13 | 14 | node* midpoint_linkedlist(node *head) 15 | { 16 | // Write your code here 17 | node *slow = head; 18 | node *fast = head->next; 19 | while(slow && fast && fast->next) 20 | { 21 | slow = slow->next; 22 | fast = fast->next->next; 23 | } 24 | return slow; 25 | } 26 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-12-Stacks-Queues/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-12-Stacks-Queues/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-12-Stacks-Queues/isBalanced.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char match(char c) 4 | { 5 | if(c == ')') 6 | return '('; 7 | else if(c == '}') 8 | return '{'; 9 | else if(c == ']') 10 | return '['; 11 | } 12 | 13 | bool checkBalanced(char *exp) { 14 | // Write your code here 15 | stack st; 16 | for(int i = 0; exp[i] != '\0'; i++) 17 | { 18 | char curr = exp[i]; 19 | if(curr == '(' || curr == '[' || curr == '{') 20 | st.push(curr); 21 | 22 | else if(curr == ')' || curr == ']' || curr == '}') 23 | { 24 | if(!st.empty()) 25 | { 26 | char top = st.top(); 27 | if(top == match(curr)) 28 | st.pop(); 29 | else 30 | return false; 31 | } 32 | else 33 | return false; 34 | } 35 | 36 | } 37 | return st.empty(); 38 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-13-Trees/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-13-Trees/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-14-BinaryTree/height.cpp: -------------------------------------------------------------------------------- 1 | // Following is the Binary Tree node structure 2 | /************** 3 | class BinaryTreeNode { 4 | public : 5 | T data; 6 | BinaryTreeNode *left; 7 | BinaryTreeNode *right; 8 | 9 | BinaryTreeNode(T data) { 10 | this -> data = data; 11 | left = NULL; 12 | right = NULL; 13 | } 14 | }; 15 | ***************/ 16 | #include 17 | using namespace std; 18 | 19 | int height(BinaryTreeNode *root) { 20 | /* Don't write main(). 21 | * Don't read input, it is passed as function argument. 22 | * Return output and don't print it. 23 | * Taking input and printing output is handled automatically. 24 | */ 25 | if(root == NULL) 26 | return 0; 27 | 28 | int l_h = height(root->left); 29 | int r_h = height(root->right); 30 | 31 | return 1 + max(l_h,r_h); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-14-BinaryTree/mirror_bt.cpp: -------------------------------------------------------------------------------- 1 | // Following is the Binary Tree node structure 2 | /************** 3 | class BinaryTreeNode { 4 | public : 5 | T data; 6 | BinaryTreeNode *left; 7 | BinaryTreeNode *right; 8 | 9 | BinaryTreeNode(T data) { 10 | this -> data = data; 11 | left = NULL; 12 | right = NULL; 13 | } 14 | }; 15 | ***************/ 16 | 17 | void mirrorBinaryTree(BinaryTreeNode* root) { 18 | // Write your code here 19 | if(root == NULL) 20 | { 21 | return; 22 | } 23 | mirrorBinaryTree(root->left); 24 | mirrorBinaryTree(root->right); 25 | BinaryTreeNode* temp = root->left; 26 | root->left = root->right; 27 | root->right = temp; 28 | } 29 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-14-BinaryTree/node_present.cpp: -------------------------------------------------------------------------------- 1 | // Following is the Binary Tree node structure 2 | /************** 3 | class BinaryTreeNode { 4 | public : 5 | T data; 6 | BinaryTreeNode *left; 7 | BinaryTreeNode *right; 8 | 9 | BinaryTreeNode(T data) { 10 | this -> data = data; 11 | left = NULL; 12 | right = NULL; 13 | } 14 | }; 15 | ***************/ 16 | 17 | bool isNodePresent(BinaryTreeNode* root, int x) { 18 | /* Don't write main(). 19 | * Don't read input, it is passed as function argument. 20 | * Return output and don't print it. 21 | * Taking input and printing output is handled automatically. 22 | */ 23 | if(root == NULL) 24 | return false; 25 | if(root->data == x) 26 | return true; 27 | 28 | return isNodePresent(root->left,x) || isNodePresent(root->right,x); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-15-BST/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-15-BST/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-15-BST/isBST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isBST(BinaryTreeNode *root, int mn = INT_MIN ,int mx = INT_MAX){ 5 | /* Don't write main(). 6 | * Don't read input, it is passed as function argument. 7 | * Return output and don't print it. 8 | * Taking input and printing output is handled automatically. 9 | */ 10 | if(root == NULL) 11 | return true; 12 | 13 | if(root->data < mn || root->data > mx) 14 | return false; 15 | 16 | return isBST(root->left,mn,root->data) && isBST(root->right,root->data,mx); 17 | 18 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-15-BST/search_elem.cpp: -------------------------------------------------------------------------------- 1 | // Following is the Binary Tree node structure 2 | /************** 3 | class BinaryTreeNode { 4 | public : 5 | T data; 6 | BinaryTreeNode *left; 7 | BinaryTreeNode *right; 8 | 9 | BinaryTreeNode(T data) { 10 | this -> data = data; 11 | left = NULL; 12 | right = NULL; 13 | } 14 | }; 15 | ***************/ 16 | 17 | BinaryTreeNode* searchInBST(BinaryTreeNode *root , int k){ 18 | /* Don't write main(). 19 | * Don't read input, it is passed as function argument. 20 | * Return output and don't print it. 21 | * Taking input and printing output is handled automatically. 22 | */ 23 | if(root == NULL) 24 | return NULL; 25 | 26 | if(root->data == k) 27 | return root; 28 | 29 | else if(root->data < k) 30 | return searchInBST(root->right,k); 31 | 32 | else if(root->data > k) 33 | return searchInBST(root->left,k); 34 | } 35 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-16-PriorityQ/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-16-PriorityQ/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-16-PriorityQ/check_max_heap.cpp: -------------------------------------------------------------------------------- 1 | //Note than i < n/2 is important 2 | 3 | bool checkMaxHeap(int arr[], int n){ 4 | /* Don't write main(). 5 | * Don't read input, it is passed as function argument. 6 | * Taking input and printing output is handled automatically. 7 | */ 8 | for(int i = 0; i < n/2; i++) 9 | { 10 | if((2*i+1) < n && arr[i] < arr[2*i+1] || arr[i] < arr[2*i+2]) 11 | return false; 12 | } 13 | 14 | return true; 15 | } 16 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-16-PriorityQ/k_largest_nlogk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | vector kLargest(int input[], int n, int k){ 5 | /* Don't write main(). 6 | * Don't read input, it is passed as function argument. 7 | * Return output and don't print it. 8 | * Taking input and printing output is handled automatically. 9 | */ 10 | 11 | priority_queue,greater> pq; 12 | for(int i = 0; i < k; i++) 13 | pq.push(input[i]); 14 | 15 | for(int i = k; i < n; i++) 16 | { 17 | if(input[i] > pq.top()) 18 | { 19 | pq.pop(); 20 | pq.push(input[i]); 21 | } 22 | } 23 | vector ans; 24 | while(!pq.empty()) 25 | { 26 | ans.push_back(pq.top()); 27 | pq.pop(); 28 | } 29 | return ans; 30 | } 31 | -------------------------------------------------------------------------------- /TRIUMPH/Lecture-16-PriorityQ/k_smallest_nlogk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | vector kSmallest(vector input, int n, int k) { 5 | // Write your code here 6 | priority_queue pq; 7 | for(int i = 0; i < k; i++) 8 | pq.push(input[i]); 9 | 10 | for(int i = k; i < n; i++) 11 | { 12 | if(input[i] < pq.top()) 13 | { 14 | pq.pop(); 15 | pq.push(input[i]); 16 | } 17 | } 18 | 19 | vector ans; 20 | while(!pq.empty()) 21 | { 22 | ans.push_back(pq.top()); 23 | pq.pop(); 24 | } 25 | 26 | return ans; 27 | } 28 | 29 | int main() 30 | { 31 | int n,k; 32 | cin >> n >> k; 33 | 34 | vector arr(n); 35 | for(int i = 0; i < n; i++) 36 | { 37 | cin >> arr[i]; 38 | } 39 | 40 | vector ans = kSmallest(arr,n,k); 41 | 42 | for(auto it : ans) 43 | cout << it << " "; 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-16-PriorityQ/k_sorted_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void kSorted(vector &arr,int n,int k) 5 | { 6 | priority_queue pq; 7 | for(int i = 0; i < k; i++) 8 | pq.push(arr[i]); 9 | 10 | int j = 0; 11 | for(int i = k; i < n; i++) 12 | { 13 | arr[j] = pq.top(); 14 | pq.pop(); 15 | pq.push(arr[i]); 16 | j++; 17 | } 18 | 19 | while(!pq.empty()) 20 | { 21 | arr[j] = pq.top(); 22 | pq.pop(); 23 | j++; 24 | } 25 | } 26 | 27 | int main() 28 | { 29 | int n,k; 30 | cin >> n >> k; 31 | 32 | vector arr(n); 33 | for(int i = 0; i < n; i++) 34 | { 35 | cin >> arr[i]; 36 | } 37 | 38 | kSorted(arr,n,k); 39 | 40 | for(auto it : arr) 41 | cout << it << " "; 42 | 43 | return 0; 44 | } 45 | 46 | //5 3 47 | //10 11 12 6 9 48 | //12 11 10 9 6 -------------------------------------------------------------------------------- /TRIUMPH/Lecture-17-Tries-Huffman/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-17-Tries-Huffman/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-17-Tries-Huffman/input_huffman.txt: -------------------------------------------------------------------------------- 1 | 6 2 | a 5 3 | b 9 4 | c 12 5 | d 13 6 | e 16 7 | f 45 8 | 9 | 11001001000111 -------------------------------------------------------------------------------- /TRIUMPH/Lecture-2-Arrays/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-2-Arrays/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-5-Rec-1/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-5-Rec-1/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-5-Rec-1/x_power_n.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int power(int x, int n) 5 | { 6 | if(n == 0) 7 | { 8 | return 1; 9 | } 10 | return x*power(x,n-1); 11 | } 12 | 13 | int main() 14 | { 15 | int x,n; 16 | cin >> x >> n; 17 | cout << power(x,n); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-6-Rec-2/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-6-Rec-2/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-6-Rec-2/interleaving.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void interleaving(char* first, char* second,string s = "") { 5 | // Write your code here 6 | if(first[0] == '\0' && second[0] == '\0') 7 | { 8 | cout << s << endl; 9 | return ; 10 | } 11 | 12 | if(first[0] != '\0') 13 | { 14 | interleaving(first+1,second,s + first[0]); 15 | } 16 | if(second[0] != '\0') 17 | { 18 | interleaving(first,second+1,s + second[0]); 19 | } 20 | 21 | } 22 | 23 | int main() 24 | { 25 | char s[100],t[100]; 26 | cin >> s >> t; 27 | 28 | interleaving(s,t); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-6-Rec-2/keypad_print.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | unordered_map keypad; 5 | 6 | void keypadCode(int n,string s = "") 7 | { 8 | if(n == 0) 9 | { 10 | cout << s << endl; 11 | return; 12 | } 13 | 14 | int quo = n / 10; 15 | int rem = n % 10; 16 | 17 | for(int i = 0; i < keypad[rem].size(); i++) 18 | { 19 | keypadCode(quo,keypad[rem][i]+s); 20 | } 21 | } 22 | 23 | int main() 24 | { 25 | keypad[2] = "abc"; 26 | keypad[3] = "def"; 27 | keypad[4] = "ghi"; 28 | keypad[5] = "jkl"; 29 | keypad[6] = "mno"; 30 | keypad[7] = "pqrs"; 31 | keypad[8] = "tuv"; 32 | keypad[9] = "wxyz"; 33 | 34 | int n; 35 | cin >> n; 36 | 37 | keypadCode(n); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-6-Rec-2/min_count.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int minCount(int n){ 5 | 6 | /* Don't write main(). 7 | * Don't read input, it is passed as function argument. 8 | * Return output and don't print it. 9 | * Taking input and printing output is handled automatically. 10 | */ 11 | if(n < 0) 12 | { 13 | return INT_MAX; 14 | } 15 | 16 | if(n == 0) 17 | { 18 | return 0; 19 | } 20 | 21 | int m_c = INT_MAX; 22 | 23 | for(int i = 1; i*i <= n; i++) 24 | { 25 | m_c = min(m_c,1 + minCount(n - i*i)); 26 | } 27 | 28 | return m_c; 29 | } 30 | 31 | int main() 32 | { 33 | int n; 34 | cin >> n; 35 | 36 | cout << minCount(n << endl; 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-6-Rec-2/print_subseq.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void subs(string in,string s = "") 6 | { 7 | if(in.empty()) 8 | { 9 | cout << s << endl; 10 | return; 11 | } 12 | subs(in.substr(1),s); 13 | subs(in.substr(1),s + in[0]); 14 | } 15 | 16 | int main() 17 | { 18 | string s; 19 | cin >> s; 20 | subs(s); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-6-Rec-2/replace_pi.cpp: -------------------------------------------------------------------------------- 1 | // Change in the given string itself. So no need to return or print anything 2 | #include 3 | using namespace std; 4 | 5 | 6 | void replacePi(char input[]) { 7 | // Write your code here 8 | if(input[0] == '\0') 9 | { 10 | return; 11 | } 12 | if(input[1] != '\0') 13 | { 14 | if(input[0] == 'p' && input[1] == 'i') 15 | { 16 | int i; 17 | input[0] = '3'; 18 | input[1] = '.'; 19 | int len = strlen(input); 20 | for(i = len -1; i >= 0; i--) 21 | input[i+2] = input[i]; 22 | input[len+2] = '\0'; 23 | input[2] = '1'; 24 | input[3] = '4'; 25 | replacePi(input); 26 | } 27 | else 28 | replacePi(input+1); 29 | } 30 | } 31 | 32 | 33 | int main() 34 | { 35 | char input[100]; 36 | cin >> input; 37 | 38 | replacePi(input); 39 | cout << input << endl; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /TRIUMPH/Lecture-6-Rec-2/ret_subseq.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int subseq(string input,string *output) 6 | { 7 | if(input.empty()) 8 | { 9 | output[0] = ""; 10 | return 1; 11 | } 12 | int k = subseq(input.substr(1),output); 13 | for(int i = 0; i < k; i++) 14 | { 15 | output[i+k] = input[0] + output[i]; 16 | } 17 | return 2*k; 18 | } 19 | 20 | int main() 21 | { 22 | string s; 23 | cin >> s; 24 | 25 | string *output = new string[1< 2 | using namespace std; 3 | 4 | class Student 5 | { 6 | public: 7 | 8 | int rollNo; 9 | 10 | private: 11 | 12 | int age; 13 | 14 | public: 15 | 16 | void setAge(int a) 17 | { 18 | if(a <= 0) 19 | return; 20 | age = a; 21 | } 22 | 23 | int getAge() 24 | { 25 | return age; 26 | } 27 | 28 | int getRoll() 29 | { 30 | return rollNo; 31 | } 32 | 33 | void setRoll(int r) 34 | { 35 | if(r <= 0) 36 | return; 37 | 38 | rollNo = r; 39 | } 40 | 41 | void display() 42 | { 43 | cout << "\nRoll No : " << rollNo; 44 | cout << "\nAge: " << age; 45 | 46 | cout << endl; 47 | } 48 | }; -------------------------------------------------------------------------------- /TRIUMPH/Lecture-8-OOPS-1/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/TRIUMPH/Lecture-8-OOPS-1/a.out -------------------------------------------------------------------------------- /TRIUMPH/Lecture-8-OOPS-1/studentUse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Student.cpp" 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | Student *s1 = new Student; 8 | Student s2; 9 | Student *s3 = new Student[2]; 10 | 11 | s3[0].setAge(100); 12 | s3[0].setRoll(30); 13 | 14 | Student *s4 = new Student(s3[0]); 15 | 16 | 17 | 18 | s1->setRoll(212); 19 | s1->setAge(21); 20 | 21 | s2.setAge(20); 22 | s2.setRoll(10); 23 | 24 | s1->display(); 25 | s2.display(); 26 | 27 | s3[0].display(); 28 | 29 | s4->display(); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Templates/HashMap/KeyHash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * Copyright 2017 HashMap Development Team 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Default hash function class 20 | template 21 | struct KeyHash { 22 | unsigned long operator()(const K &key) const 23 | { 24 | return reinterpret_cast(key) % tableSize; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /V: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/V -------------------------------------------------------------------------------- /WIC-PreXtreme/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/WIC-PreXtreme/a.out -------------------------------------------------------------------------------- /WIC-PreXtreme/akbar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int t; 9 | cin>>t; 10 | for(int t0=0;t0>n>>m; 14 | vector graph(n); 15 | for(int i=0;i>graph[i]; 17 | 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /WIC-PreXtreme/akbarcpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/WIC-PreXtreme/akbarcpp -------------------------------------------------------------------------------- /WIC-PreXtreme/annabelle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin>>t; 9 | for(int i=0;i>n; 13 | vector arr(n); 14 | for(int j=0;i>arr[i]; 16 | 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /WIC-PreXtreme/aravinda.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long n; 9 | cin>>n; 10 | for(int i=0;i>x; 14 | string s=bitset<64>(x).to_string(); 15 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long t; 8 | cin>>t; 9 | for(long i=0;i>x1>>y1>>x2>>y2; 13 | long xDiff=x2-x1,yDiff=y2-y1; 14 | if(abs(xDiff)==abs(yDiff)) 15 | cout<<1< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | long n; 10 | cin>>n; 11 | vector array(n); 12 | unordered_map countMap; 13 | for(long i=0;i>array[i]; 16 | countMap[array[i]]++; 17 | } 18 | long q; 19 | cin>>q; 20 | for(long i=0;i>val; 24 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin>>n; 9 | string a="p++"; 10 | string b="++p"; 11 | string c="--p"; 12 | string d="p--"; 13 | string e="p=0"; 14 | int finalVal=0; 15 | for(int i=0;i>input; 19 | if(input.compare(a)==0 || input.compare(b)==0) 20 | finalVal++; 21 | else if(input.compare(c)==0 || input.compare(d)==0) 22 | finalVal--; 23 | else if(input.compare(e)==0) 24 | finalVal=0; 25 | cout< 2 | using namespace std; 3 | 4 | vector z(51,0); 5 | 6 | void zfunction(string s) 7 | { 8 | int n = s.size(); 9 | int L = 0, R = 0; 10 | for (int i = 1; i < n; i++) 11 | { 12 | if (i > R) 13 | { 14 | L = R = i; 15 | while (R < n && s[R-L] == s[R]) R++; 16 | z[i] = R-L; R--; 17 | } 18 | else 19 | { 20 | int k = i-L; 21 | if (z[k] < R-i+1) 22 | z[i] = z[k]; 23 | else 24 | { 25 | L = i; 26 | while (R < n && s[R-L] == s[R]) R++; 27 | z[i] = R-L; R--; 28 | } 29 | } 30 | } 31 | } 32 | 33 | int main() 34 | { 35 | string s; 36 | cin >> s; 37 | zfunction(s); 38 | cout << z[s.size()-1]; 39 | return 0; 40 | } -------------------------------------------------------------------------------- /World-Codesprint12/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/World-Codesprint12/a.out -------------------------------------------------------------------------------- /Zoho-Practice/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/Zoho-Practice/a.out -------------------------------------------------------------------------------- /Zoho-Practice/alternate_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | vector arr(n); 10 | for(int i = 0; i < n; i++) 11 | cin >> arr[i]; 12 | 13 | sort(arr.begin(),arr.end()); 14 | 15 | int i = 0; 16 | int j = n-1; 17 | vector brr(n); 18 | int k = 0; 19 | 20 | while(i < n && j >= 0) 21 | { 22 | brr[k++] = arr[j--]; 23 | brr[k++] = arr[i++]; 24 | } 25 | for(auto it : brr) 26 | { 27 | cout << it << " "; 28 | } 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /a.java: -------------------------------------------------------------------------------- 1 | class Amrith{ 2 | 3 | } -------------------------------------------------------------------------------- /a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/a.out -------------------------------------------------------------------------------- /accs.py: -------------------------------------------------------------------------------- 1 | q = int(raw_input().strip()) 2 | for a0 in xrange(q): 3 | n = int(raw_input().strip()) 4 | a = map(int, raw_input().strip().split(' ')) 5 | l=sorted(a) 6 | for i in range(0,len(a)-1): 7 | if(abs()) -------------------------------------------------------------------------------- /accsort.py: -------------------------------------------------------------------------------- 1 | import copy 2 | q = int(raw_input().strip()) 3 | for k in xrange(q): 4 | n = int(raw_input().strip()) 5 | a = map(int, raw_input().strip().split(' ')) 6 | org=copy.copy(a) 7 | length=len(a)-1 8 | a=sorted(a) 9 | # for i in range(0,length): 10 | # for j in range(0,length-i): 11 | # if(a[j]>a[j+1]): 12 | # temp=a[j] 13 | # a[j]=a[j+1] 14 | # a[j+1]=temp 15 | for i in range(0,length): 16 | for j in range(0,length-i): 17 | if(abs(org[j]-org[j+1])==1): 18 | if(org[j]>org[j+1]): 19 | temp=org[j] 20 | org[j]=org[j+1] 21 | org[j+1]=temp 22 | if(a==org): 23 | print "Yes" 24 | else: 25 | print "No" -------------------------------------------------------------------------------- /alternating_char.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int alternatingCharacters(string s){ 5 | // Complete this function 6 | int count=0; 7 | for(int i=0;i> q; 18 | for(int a0 = 0; a0 < q; a0++){ 19 | string s; 20 | cin >> s; 21 | int result = alternatingCharacters(s); 22 | cout << result << endl; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /anagram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int anagram(string s) 6 | { 7 | // Complete this function 8 | int len=s.size(); 9 | 10 | if(len%2!=0) 11 | return -1; 12 | 13 | string s1=s.substr(0,len/2); 14 | string s2=s.substr(len/2,len/2); 15 | map charMap; 16 | 17 | for(int i=0;i> q; 34 | for(int a0 = 0; a0 < q; a0++){ 35 | string s; 36 | cin >> s; 37 | int result = anagram(s); 38 | cout << result << endl; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | s,t = raw_input().strip().split(' ') 5 | s,t = [int(s),int(t)] 6 | a,b = raw_input().strip().split(' ') 7 | a,b = [int(a),int(b)] 8 | m,n = raw_input().strip().split(' ') 9 | m,n = [int(m),int(n)] 10 | apple = map(int,raw_input().strip().split(' ')) 11 | orange = map(int,raw_input().strip().split(' ')) 12 | app_count=0 13 | org_count=0 14 | for i in apple: 15 | dist=0 16 | if i>=0: 17 | dist=a+i 18 | print(dist) 19 | if(dist>=s and dist<=t): 20 | app_count+=1 21 | for i in orange: 22 | dist=0 23 | if i<=0: 24 | dist=b+i 25 | print(dist) 26 | if(disdist<=t and dist>=s): 27 | org_count+=1 28 | print(app_count) 29 | print(org_count) 30 | 31 | 32 | -------------------------------------------------------------------------------- /append_delete.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | 26 | int main() 27 | { 28 | string s; 29 | cin >> s; 30 | string t; 31 | cin >> t; 32 | int k; 33 | cin >> k; 34 | int i=0; 35 | while(s[i]==t[i]) 36 | { 37 | i++; 38 | } 39 | int diff=s.size()+t.size()-2*i; 40 | string res=((diff <= k && diff%2 == k%2) || s.size() + t.size() < k ? "Yes" : "No"); 41 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(){ 10 | long long int s,t,a,b,m,n; 11 | scanf("%lld %lld",&s,&t); 12 | scanf("%lld %lld",&a,&b); 13 | scanf("%lld %lld",&m,&n); 14 | long long int apple,orange,apple_count=0,orange_count=0; 15 | long long int i,dist=0; 16 | for(i = 0; i < m; i++){ 17 | scanf("%lld",&apple); 18 | if(apple>=0) 19 | { 20 | dist=a+apple; 21 | if(dist>=s) 22 | apple_count+=1; 23 | } 24 | } 25 | for(i = 0; i < n; i++){ 26 | scanf("%lld",&orange); 27 | if(orange<=0) 28 | { 29 | dist=b+orange; 30 | if(dist<=t) 31 | orange_count+=1; 32 | } 33 | } 34 | printf("%lld\n%lld",apple_count,orange_count); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /arr[arr_i]: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/arr[arr_i] -------------------------------------------------------------------------------- /b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/b -------------------------------------------------------------------------------- /bad_dream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long t; 8 | cin>>t; 9 | for(long i=0;i>x1>>y1>>x2>>y2>>k; 13 | long xDiff=x2-x1,yDiff=y2-y1; 14 | long val=abs(xDiff)+abs(yDiff); 15 | if(val<=k) 16 | cout<<"YES\n"; 17 | else 18 | cout<<"NO\n"; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /baker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int n,m,i,j,k,a,b,c,dd,c0,d0; 9 | int d[1005]; 10 | 11 | int main() 12 | { 13 | cin>>n>>m>>c0>>d0; 14 | for(i=c0;i<=n;i++) 15 | d[i]=i/c0*d0; 16 | for(i=1;i<=m;i++) 17 | { 18 | cin>>a>>b>>c>>dd; 19 | for(j=1;j<=a/b;j++) 20 | for(k=n;k>=c;k--) 21 | d[k]=max(d[k],d[k-c]+dd); 22 | } 23 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int max_gold_coins() 10 | { 11 | 12 | } 13 | int main() { 14 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 15 | int n,m,c0,d0; 16 | cin>>n>>m>>c0>>d0; 17 | vector> input(m,vector(4)); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /bday_chocolate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int solve(int n, vector < int > s, int d, int m){ 6 | int j,k=1,t=m,sum=0,count=0; 7 | for(int i=0;i> n; 24 | vector s(n); 25 | for(int s_i = 0; s_i < n; s_i++){ 26 | cin >> s[s_i]; 27 | } 28 | int d; 29 | int m; 30 | cin >> d >> m; 31 | int result = solve(n, s, d, m); 32 | cout << result << endl; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /beautiful_binary_string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int minSteps(int n, string B){ 6 | // Complete this function 7 | int count=0; 8 | for(int i=0;i> n; 22 | string B; 23 | cin >> B; 24 | int result = minSteps(n, B); 25 | cout << result << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /beautiful_triplets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n,d; 11 | cin>>n>>d; 12 | vector sequence(n); 13 | for(int i=0;i>sequence[i]; 15 | int count=0; 16 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() 11 | { 12 | int t; 13 | cin>>t; 14 | for(int a=0;a>s; 19 | bool val = next_permutation(s.begin(), s.end()); 20 | if (val == false) 21 | cout << "no word" << endl; 22 | else 23 | cout< 2 | #include 3 | using namespace std; 4 | int maxLengthOnes(string s) 5 | { 6 | int count=0,result=0; 7 | for(int i=0;i>s; 23 | cout<<"\n"< 2 | 3 | using namespace std; 4 | 5 | int digSum(int n) 6 | { 7 | int ans = 0; 8 | while(n != 0) 9 | { 10 | ans += n%10; 11 | n/= 10; 12 | } 13 | return ans; 14 | } 15 | string canConstruct(vector a) 16 | { 17 | // Return "Yes" or "No" denoting whether you can construct the required number. 18 | long long int sum = 0; 19 | for(int i = 0; i < a.size(); i++) 20 | { 21 | sum += digSum(a[i]); 22 | } 23 | if(sum % 3 == 0) 24 | { 25 | return "Yes"; 26 | } 27 | else 28 | return "No"; 29 | } 30 | 31 | int main() { 32 | int t; 33 | cin >> t; 34 | for(int a0 = 0; a0 < t; a0++){ 35 | int n; 36 | cin >> n; 37 | vector a(n); 38 | for(int a_i = 0; a_i < n; a_i++){ 39 | cin >> a[a_i]; 40 | } 41 | string result = canConstruct(a); 42 | cout << result << endl; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /candies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int candies(int n, vector arr) { 6 | // Complete this function 7 | 8 | } 9 | 10 | int main() { 11 | int n; 12 | cin >> n; 13 | vector arr(n); 14 | for(int arr_i = 0; arr_i < n; arr_i++){ 15 | cin >> arr[arr_i]; 16 | } 17 | int result = candies(n, arr); 18 | cout << result << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /candies_dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | long long candies(int n, vector arr) { 6 | // Complete this function 7 | vector dp(n); 8 | dp[0] = 1; 9 | 10 | for(int i = 1; i < n; i++) 11 | dp[i] = 1; 12 | 13 | for(int i = 1; i < n; i++) 14 | { 15 | if(arr[i] > arr[i-1]) 16 | dp[i] = dp[i-1] + 1; 17 | } 18 | 19 | for(int i = n-2 ; i >= 0 ; i--) 20 | { 21 | if(arr[i] > arr[i+1]) 22 | { 23 | dp[i] = max(dp[i],dp[i+1] + 1); 24 | } 25 | } 26 | long long sum = 0; 27 | 28 | for(int i = 0; i < n; i++) 29 | sum += dp[i]; 30 | 31 | return sum; 32 | } 33 | 34 | int main() { 35 | int n; 36 | cin >> n; 37 | vector arr(n); 38 | for(int arr_i = 0; arr_i < n; arr_i++){ 39 | cin >> arr[arr_i]; 40 | } 41 | long long result = candies(n, arr); 42 | cout << result << endl; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /cavity_map.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int i,j; 9 | vector grid(n); 10 | for(int grid_i = 0; grid_i < n; grid_i++){ 11 | cin >> grid[grid_i]; 12 | } 13 | for(i=1;i(grid[i-1][j]-'0') && elem>(grid[i+1][j]-'0') && elem>(grid[i][j+1]-'0') && elem>(grid[i][j-1]-'0')) 19 | { 20 | grid[i][j]='X'; 21 | } 22 | } 23 | } 24 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main(){ 9 | int t; 10 | cin >> t; 11 | int arr[t]; 12 | for(int a0 = 0; a0 < t; a0++){ 13 | int n; 14 | int c; 15 | int m; 16 | cin >> n >> c >> m; 17 | int sweet=n/c; 18 | int wrappers=sweet; 19 | while(wrappers>=m) 20 | { 21 | int temp=wrappers/m; 22 | wrappers=temp+(wrappers%m); 23 | sweet+=temp; 24 | } 25 | arr[a0]=sweet; 26 | } 27 | for(int i=0;i 2 | #include 3 | int main() 4 | { 5 | long q; 6 | std::cin >> q; 7 | long arr[q]; 8 | for(long a0 = 0; a0 < q; a0++){ 9 | long sweet; 10 | long wrap; 11 | long k; 12 | std::cin >>sweet>>wrap>>k; 13 | long wrappers=sweet+wrap; 14 | while(wrappers>=k){ 15 | long temp=wrappers/k; 16 | wrappers=temp+(wrappers%k); 17 | sweet+=temp; 18 | } 19 | arr[a0]=sweet; 20 | } 21 | for(long i=0;i 2 | #include 3 | int main() 4 | { 5 | int q; 6 | cin>>q; 7 | for(int q0=0;10>n>>b; 11 | vector heights(n); 12 | for(int i=0;i>heights[i]; 14 | int max=heights[0]; 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /coin_change.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | long getWays(long n, vector < long > c){ 6 | // Complete this function 7 | vector table(n+1); 8 | table[0]=1; 9 | for(long i=0;i> n >> m; 24 | vector c(m); 25 | for(int c_i = 0; c_i < m; c_i++){ 26 | cin >> c[c_i]; 27 | } 28 | // Print the number of ways of making change for 'n' units using coins having the values given by 'c' 29 | long ways = getWays(n, c); 30 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | vector genes(n); 10 | 11 | for(int genes_i = 0; genes_i < n; genes_i++){ 12 | cin >> genes[genes_i]; 13 | } 14 | 15 | vector health(n); 16 | 17 | for(int health_i = 0; health_i < n; health_i++){ 18 | cin >> health[health_i]; 19 | } 20 | 21 | int s; 22 | cin >> s; 23 | for(int a0 = 0; a0 < s; a0++){ 24 | int first; 25 | int last; 26 | string d; 27 | cin >> first >> last >> d; 28 | // your code goes here 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /dijkstra.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | from heapq import * 3 | 4 | def dijkstra(edges, f, t): 5 | g = defaultdict(list) 6 | for l,r,c in edges: 7 | g[l].append((c,r)) 8 | 9 | q, seen = [(0,f,())], set() 10 | while q: 11 | (cost,v1,path) = heappop(q) 12 | if v1 not in seen: 13 | seen.add(v1) 14 | path = (v1, path) 15 | if v1 == t: return (cost, path) 16 | for c, v2 in g.get(v1, ()): 17 | if v2 not in seen: 18 | heappush(q, (cost+c, v2, path)) 19 | 20 | return float("inf") 21 | 22 | if __name__ == "__main__": 23 | edges = [ 24 | ("2","3",6),("1","3",6) 25 | ] 26 | 27 | print "=== Dijkstra ===" 28 | print edges 29 | print "A -> E:" 30 | print dijkstra(edges, "1", "2") 31 | print "F -> G:" 32 | print dijkstra(edges, "1", "3") 33 | print dijkstra(edges, "1", "4") -------------------------------------------------------------------------------- /elec.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def getMoneySpent(keyboards, drives, s): 4 | mix=[(x,y,x+y) for x in keyboards for y in drives] 5 | maxCost=-1 6 | for t in mix: 7 | if(t[2]>maxCost and t[2]<=s): 8 | maxCost=t[2] 9 | return maxCost 10 | s,n,m = raw_input().strip().split(' ') 11 | s,n,m = [int(s),int(n),int(m)] 12 | keyboards = map(int, raw_input().strip().split(' ')) 13 | drives = map(int, raw_input().strip().split(' ')) 14 | # The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items 15 | moneySpent = getMoneySpent(keyboards, drives, s) 16 | print(moneySpent) -------------------------------------------------------------------------------- /electo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // create a vector to store int 7 | vector vec; 8 | int i; 9 | 10 | // display the original size of vec 11 | cout << "vector size = " << vec.size() << endl; 12 | 13 | // push 5 values into the vector 14 | for(i = 0; i < 5; i++){ 15 | vec.push_back(i); 16 | } 17 | 18 | // display extended size of vec 19 | cout << "extended vector size = " << vec.size() << endl; 20 | 21 | // access 5 values from the vector 22 | for(i = 0; i < 5; i++){ 23 | cout << "value of vec [" << i << "] = " << vec[i] << endl; 24 | } 25 | 26 | // use iterator to access the values 27 | vector::iterator v = vec.begin(); 28 | while( v != vec.end()) { 29 | cout << "value of v = " << *v << endl; 30 | v++; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /emas_supercomputer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() 10 | { 11 | int n,m; 12 | cin>>n>>m; 13 | int i,j; 14 | vector cells(n); 15 | for(i=0;i>cells[i]; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /eq.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | string findEq(vector> forces) 10 | { 11 | int f[]={0,0,0}; 12 | for(int i=0;i>n; 38 | vector> forces(n,vector(3)); 39 | for(int i=0;i>forces[i][j]; 43 | } 44 | cout< 2 | #include 3 | using namespace std; 4 | 5 | bool evalBoolExp(string s) 6 | { 7 | for(int i=0;i>s; 34 | } -------------------------------------------------------------------------------- /extract_unique_characters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | char* uniqueChar(char *str){ 8 | // Write your code here 9 | 10 | } 11 | 12 | int main() 13 | { 14 | string s; 15 | cin>>s; 16 | cout< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int t; 10 | cint >> t; 11 | while(t--) 12 | { 13 | int a,n,p; 14 | 15 | cin >> a >> n >> p; 16 | 17 | if(a == 1) 18 | { 19 | cout << a%p < 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | int main() { 26 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /find_closest_n_div_m.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int findClosestNum(int n,int m) 4 | { 5 | int q,n1,n2; 6 | q=n/m; 7 | n1=q*m; 8 | 9 | if(n*m>0) 10 | n2=(m*(q+1)); 11 | else 12 | n2=(m*(q-1)); 13 | 14 | // cout<>n>>m; 27 | 28 | cout<<"\n"< 2 | 3 | using namespace std; 4 | 5 | int charDiff(char a,char b) 6 | { 7 | return abs(a-b); 8 | } 9 | 10 | string funnyString(string s){ 11 | // Complete this function 12 | int len=s.size()-1; 13 | int flag=0; 14 | for(int i=0;i> q; 34 | for(int a0 = 0; a0 < q; a0++){ 35 | string s; 36 | cin >> s; 37 | string result = funnyString(s); 38 | cout << result << endl; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /game_of_thrones_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | string gameOfThrones(string s) 6 | { 7 | // Complete this function 8 | map charMap; 9 | int len = s.size(); 10 | int i = 0; 11 | 12 | for(;i> s; 38 | string result = gameOfThrones(s); 39 | cout << result << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /grid_challenge.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 9 | int n,i=0; 10 | scanf("%d",&n); 11 | char array[100][100]; 12 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /hackerrank_in_a_string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int q; 7 | cin >> q; 8 | for(int a0 = 0; a0 < q; a0++){ 9 | string s; 10 | cin >> s; 11 | // your code goes here 12 | string str="hackerrank"; 13 | if(s.size() 2 | void main() 3 | { 4 | cout<<"\nHello world"; 5 | } -------------------------------------------------------------------------------- /help_ferb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() { 11 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 12 | string s; 13 | cin>>s; 14 | map mapSum; 15 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int q; 12 | cin>>q; 13 | for(int m=0;m>n; 17 | int nimsum=0; 18 | vector piles(n); 19 | for(int i=0;i>piles[i]; 22 | } 23 | nimsum=piles[0]; 24 | for(int i=1;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main(){ 9 | int d1; 10 | int m1; 11 | int y1; 12 | cin >> d1 >> m1 >> y1; 13 | int d2; 14 | int m2; 15 | int y2; 16 | cin >> d2 >> m2 >> y2; 17 | int fine=0; 18 | int diff_d=d1-d2; 19 | int diff_m=m1-m2; 20 | int diff_y=y1-y2; 21 | if(diff_d>0 && diff_m==0 && diff_y==0) 22 | fine=15*diff_d; 23 | else if(diff_m>0 && diff_y==0) 24 | fine=500*diff_m; 25 | else if(diff_y>0) 26 | fine=10000; 27 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int calc_lis(vector val,int n) 9 | { 10 | vector lis(n); 11 | 12 | int i=0,j=0; 13 | 14 | for(;i>n; 39 | 40 | vector val(n); 41 | 42 | for(int i=0;i>val[i]; 44 | 45 | cout< 2 | 3 | using namespace std; 4 | 5 | int theLoveLetterMystery(string s){ 6 | // Complete this function 7 | int len=s.size(); 8 | int count=0; 9 | if(len%2==0) 10 | { 11 | for(int i=len/2,k=1;i> q; 29 | for(int a0 = 0; a0 < q; a0++){ 30 | string s; 31 | cin >> s; 32 | int result = theLoveLetterMystery(s); 33 | cout << result << endl; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /magicSquare.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int vect_diff(vectora,vectorb); 6 | int main() 7 | { 8 | vector input(9); 9 | for(int i=0;i<9;i++) 10 | cin>>input[i]; 11 | vector> magicSquares (8,vector(9)); 12 | magicSquares={{8,1,6,3,5,7,4,9,2},{4,9,2,3,5,7,8,1,6},{6,1,8,7,5,3,2,9,4}, 13 | {2,9,4,7,5,3,6,1,8},{8,3,4,1,5,9,6,7,2},{6,7,2,1,5,9,8,3,4}, 14 | {4,3,8,9,5,1,2,7,6},{2,7,6,9,5,1,4,3,8}}; 15 | int diff=1000; 16 | for(int i=0;i<8;i++) 17 | { 18 | diff=min(diff,vect_diff(input,magicSquares[i])); 19 | } 20 | printf("%d\t",diff); 21 | return 0; 22 | } 23 | int vect_diff(vector a,vector b) 24 | { 25 | vector diff_vect(9); 26 | int sum=0; 27 | for(int i=0;i<9;i++) 28 | { 29 | diff_vect[i]=abs(a[i]-b[i]); 30 | sum+=diff_vect[i]; 31 | } 32 | return sum; 33 | 34 | } -------------------------------------------------------------------------------- /manasa_stones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() { 11 | int q; 12 | cin>>q; 13 | for(int a0=0;a0>n>>a>>b; 17 | set finalSet; 18 | set::iterator it; 19 | n--; 20 | for(int i=0;i<=n;i++) 21 | { 22 | int combo=i*a+(n-i)*b; 23 | finalSet.insert(combo); 24 | } 25 | for(it=finalSet.begin();it!=finalSet.end();++it) 26 | cout<<*it<<" "; 27 | cout<<"\n"; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /marcs_cakewalk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | vector calories(n); 9 | for(int calories_i = 0; calories_i < n; calories_i++){ 10 | cin >> calories[calories_i]; 11 | } 12 | sort(calories.begin(),calories.end()); 13 | long miles=0; 14 | int k=0; 15 | for(int i=calories.size()-1;i>=0;i--) 16 | { 17 | miles+=pow(2,k)*calories[i]; 18 | k++; 19 | } 20 | cout< 2 | void sort(int a[2][2],int r,int c); 3 | int main() 4 | { 5 | int i,j; 6 | int a[2][2]; 7 | a[0][0]=12; 8 | a[0][1]=1; 9 | a[1][0]=2; 10 | a[1][1]=11; 11 | sort(a,2,2); 12 | return 0; 13 | 14 | } 15 | void sort(int a[2][2],int r,int c) 16 | { 17 | int b[4]; 18 | int i,j,k=0; 19 | for(i=0;i<2;i++) 20 | for(j=0;j<2;j++) 21 | { 22 | b[k]=a[i][j]; 23 | k++; 24 | } 25 | for(i=0;i<4;i++) 26 | for(j=0;j<4-i;j++) 27 | { 28 | if(b[j]>b[j+1]) 29 | { 30 | int t=b[j]; 31 | b[j]=b[j+1]; 32 | b[j+1]=t; 33 | } 34 | } 35 | printf("Solve:"); 36 | for(i=0;i<4;i++) 37 | printf("\t%d",b[i]); 38 | } 39 | -------------------------------------------------------------------------------- /max_product_subarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int maxProduct(vector arr,int n) 6 | { 7 | int max_end_here=1,max_so_far=1,min_end_here=1; 8 | 9 | for(int i=0;i0) 12 | { 13 | max_end_here=max_end_here*arr[i]; 14 | min_end_here=min(min_end_here*arr[i],1); 15 | } 16 | else if(arr[i]==0) 17 | { 18 | max_end_here=1; 19 | min_end_here=1; 20 | } 21 | else 22 | { 23 | int temp=max_end_here; 24 | max_end_here=max(min_end_here*arr[i],1); 25 | min_end_here=temp*arr[i]; 26 | } 27 | if(max_so_far>n; 36 | vector arr(n); 37 | for(int i=0;i>arr[i]; 39 | cout<<"\n"< 2 | #include 3 | using namespace std; 4 | 5 | long long minimumAbsoluteDifference(long long n, vector arr) { 6 | // Complete this function 7 | long long min=INT8_MAX; 8 | sort(arr.begin(),arr.end()); 9 | for(long long i=0;i> n; 21 | vector arr(n); 22 | for(long long arr_i = 0; arr_i < n; arr_i++){ 23 | cin >> arr[arr_i]; 24 | } 25 | long long result = minimumAbsoluteDifference(n, arr); 26 | cout << result << endl; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /missing_numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() { 11 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 12 | int n,m; 13 | cin >> n; 14 | map freqMap1; 15 | for(int i = 0; i < n; i++) 16 | { 17 | int k; 18 | cin >> k; 19 | freqMap1[k]++; 20 | } 21 | 22 | cin >> m; 23 | map freqMap2; 24 | for(int i = 0; i < m; i++) 25 | { 26 | int k; 27 | cin >> k; 28 | freqMap2[k]++; 29 | } 30 | 31 | for(auto it: freqMap2) 32 | { 33 | if(freqMap1[it.first] < it.second) 34 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(){ 10 | int n; 11 | scanf("%d",&n); 12 | int grade[n],d,diff,i; 13 | for(int i = 0; i < n; i++){ 14 | scanf("%d",&grade[i]); 15 | if(grade[i]>=38){ 16 | d=(grade[i]/5)+1; 17 | diff=grade[i]-5*d; 18 | if(diff<0) 19 | diff*=-1; 20 | if(diff<3) 21 | grade[i]+=diff; 22 | } 23 | } 24 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() 11 | { 12 | int n,k; 13 | cin>>n>>k; 14 | int i,j; 15 | vector nos(n); 16 | unordered_map map; 17 | for(i=0;i>nos[i]; 20 | map[nos[i]%k]+=1; 21 | } 22 | int count=min(map[0],1); 23 | for(i=1;i<(k/2)+1;i++) 24 | { 25 | if(i!=k-i) 26 | { 27 | count+=max(map[i],map[k-i]); 28 | } 29 | } 30 | if(k%2==0) 31 | count+=1; 32 | cout< 2 | 3 | using namespace std; 4 | 5 | int has(int *a, int n, int x, int k) { 6 | if(k==0) 7 | return 1; 8 | if(n==0 && k!=0) 9 | return 0; 10 | if(a[n-1] == x) { 11 | return has(a, n-1, x, k-1); 12 | } else { 13 | return has(a, n-1, x, k); 14 | } 15 | } 16 | int main() 17 | 18 | { 19 | int a[]={1,2,3,5,6,2,2,6}; 20 | cout< 2 | 3 | using namespace std; 4 | 5 | int max3(int x, int y, int z) { 6 | if(x >= y) 7 | { 8 | if(x>=z) 9 | return x; 10 | } 11 | else if(y >= z) 12 | { 13 | return y; 14 | } 15 | return z; 16 | } 17 | int main() 18 | { 19 | cout< 2 | 3 | using namespace std; 4 | 5 | int maxConsecutive(int *a, int n, int m) { 6 | int sum = 0; 7 | for(int i = 0; i < m; i++) { 8 | sum += a[i]; 9 | } 10 | int max = sum; 11 | for(int i = m; i < n; i++) { 12 | 13 | } 14 | return max; 15 | } -------------------------------------------------------------------------------- /npat/q6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int checkAddSeq(int *x, int *y, int n) { 6 | for(int i = 0; i < n; i++) { 7 | int m=0,temp=0; 8 | while(m<=i) 9 | { 10 | temp+=x[m]; 11 | m++; 12 | } 13 | if(y[i]!=temp) 14 | { 15 | return 0; 16 | } 17 | 18 | } 19 | return 1; 20 | } 21 | int main() 22 | { 23 | int a[]={1,2,5,4,3}; 24 | int b[]={1,3,8,12,15}; 25 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | string input; 8 | vector strs(1000); 9 | int size=0; 10 | while (getline(std::cin, input)) 11 | { 12 | if (input.empty()) 13 | break; 14 | strs[size]=(input); 15 | size++; 16 | } 17 | int n=size/2; 18 | for(int i=n;i 2 | 3 | using namespace std; 4 | 5 | bool checkPalin(string s,int start,int end) 6 | { 7 | bool res=true; 8 | int k=end; 9 | for(int i=start;i> q; 40 | for(int a0 = 0; a0 < q; a0++){ 41 | string s; 42 | cin >> s; 43 | int result = palindromeIndex(s); 44 | cout << result << endl; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /parity_game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int smallestSizeSubsequence(int n, vector A,int sum) { 6 | if(sum%2==0) 7 | return 0; 8 | else 9 | { 10 | int n_odd=0; 11 | int n_even=0; 12 | for(int i=0;i> n; 32 | vector A(n); 33 | int sum=0; 34 | for(int A_i = 0; A_i < n; A_i++){ 35 | cin >> A[A_i]; 36 | sum+=A[A_i]; 37 | } 38 | int result = smallestSizeSubsequence(n, A,sum); 39 | cout << result << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /password_cracker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | void length_pass(string arr[],string input,string output="") 9 | { 10 | 11 | 12 | } 13 | 14 | int main() { 15 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 16 | int t; 17 | cin>>t; 18 | for(int t0=0;t0>n; 22 | string *arr=new string[n]; 23 | string *output=new string[n]; 24 | 25 | for(int i=0;i>arr[i]; 27 | 28 | string input; 29 | cin>>input; 30 | length_pass(arr,input); 31 | 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /pattern.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/pattern.py -------------------------------------------------------------------------------- /pgm1.py: -------------------------------------------------------------------------------- 1 | n = int(raw_input().strip()) 2 | height = map(int,raw_input().strip().split(' ')) 3 | Max=height[0] 4 | for i in range(0,len(height)-1): 5 | if height[i]>Max: 6 | Max=height[i] 7 | count=0 8 | for i in range(0,len(height)): 9 | if height[i]==Max: 10 | count+=1 11 | print count 12 | -------------------------------------------------------------------------------- /pick.py: -------------------------------------------------------------------------------- 1 | #!/bin/python 2 | 3 | import sys 4 | 5 | n = int(raw_input().strip()) 6 | a = map(int,raw_input().strip().split(' ')) 7 | a.sort() 8 | count=0 9 | print(a) 10 | for i in range(n-1): 11 | if abs(a[i]-a[i+1])<=1: 12 | count+=1 13 | else: 14 | count=0 15 | print count 16 | -------------------------------------------------------------------------------- /pick_numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | 26 | 27 | int main(){ 28 | int n; 29 | cin >> n; 30 | vector a(n); 31 | vector count(100); 32 | for(int i = 0;i < n;i++){ 33 | cin >> a[i]; 34 | count[a[i]]++; 35 | } 36 | int max=0; 37 | for(int i=0;imax) 40 | { 41 | max=count[i]+count[i+1]; 42 | } 43 | } 44 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int sum_as_nth_pow(int num,int power,int base,int sum) 9 | { 10 | int curr=pow(base,power); 11 | 12 | if((curr+sum)==num) 13 | return 1; 14 | if(sum>num || curr>num) 15 | return 0; 16 | else 17 | { 18 | return sum_as_nth_pow(num,power,base+1,sum+curr)+sum_as_nth_pow(num,power,base+1,sum); 19 | } 20 | } 21 | 22 | int main() { 23 | /* Enter your cootherotherotherde here. Read input from STDIN. Print output to STDOUT */ 24 | int x,n; 25 | cin>>x; 26 | cin>>n; 27 | cout<1918: 13 | if (year%400==0) or (year%4==0 and year%100!=0): 14 | leap=1 15 | else: 16 | return "26.09.1918" 17 | if leap: 18 | year_list=[31,29,31,30,31,30,31,31,30,31,30,31] 19 | for i in range(12): 20 | year_list_cum[i]=sum(year_list[:i+1]) 21 | days_left=256-year_list_cum[7] 22 | String=str(days_left)+".09."+str(year) 23 | return String 24 | else: 25 | year_list=[31,28,31,30,31,30,31,31,30,31,30,31] 26 | for i in range(12): 27 | year_list_cum[i]=sum(year_list[:i+1]) 28 | days_left=256-year_list_cum[7] 29 | String=str(days_left)+".09."+str(year) 30 | return String 31 | 32 | year = int(raw_input().strip()) 33 | result = solve(year) 34 | print(result) 35 | -------------------------------------------------------------------------------- /q: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amrithm98/Competitive-Coding/544ca2ec66c0af8f8a448774a6744d2470feb1f4/q -------------------------------------------------------------------------------- /q8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | void mostFreq3(int *a, int n, int b[3]) { 8 | int i=0; 9 | unordered_map countMap; 10 | for(i=0;i> n; 27 | for(i=0;i> a[i]; 29 | } 30 | 31 | mostFreq3(a,n,b); 32 | for(i=0; i<3; i++) 33 | cout << b[i] << " "; 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /ques2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int q; 7 | cin >> q; 8 | for(int a0 = 0; a0 < q; a0++){ 9 | int n; 10 | int m; 11 | int k; 12 | cin >> n >> m >> k; 13 | vector< vector > h(n,vector(m)); 14 | for(int h_i = 0;h_i < n;h_i++){ 15 | for(int h_j = 0;h_j < m;h_j++){ 16 | cin >> h[h_i][h_j]; 17 | } 18 | } 19 | // Write Your Code Here 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /recursive_digit_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | long long int superDigit(long long int n,long long int k) 9 | { 10 | if(n/10==0) 11 | { 12 | return n; 13 | } 14 | long long int digSum=0; 15 | long long int temp=n; 16 | while(temp!=0) 17 | { 18 | digSum+=temp%10; 19 | temp/=10; 20 | } 21 | digSum*=k; 22 | cout<>n>>k; 31 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | 26 | 27 | int main(){ 28 | 29 | string s; 30 | cin >> s; 31 | long n,i; 32 | cin >> n; 33 | long len=s.length(); 34 | long quo=n/len; 35 | long rem=n%len; 36 | int nos_a=count(s.begin(),s.end(),'a'); 37 | long sum=0; 38 | int rem_a=count(s.begin(),s.begin()+rem,'a'); 39 | sum+=(nos_a*quo+rem_a); 40 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | int main() { 26 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 27 | int n,i; 28 | cin>>n; 29 | unordered_map a; 30 | for(i=1;i<=n;i++) 31 | { 32 | int m; 33 | cin>>m; 34 | a[m]=i; 35 | } 36 | for(i=1;i<=n;i++) 37 | { 38 | int x=i; 39 | int t=a[x]; 40 | x=a[t]; 41 | cout< 2 | 3 | using namespace std; 4 | 5 | 6 | int charDiff(char a,char b) 7 | { 8 | return (a-b); 9 | } 10 | string beatiful(string s) 11 | { 12 | int len=s.size(); 13 | for(int i=0;i> q; 24 | for(int a0 = 0; a0 < q; a0++){ 25 | string s; 26 | cin >> s; 27 | // your code goes here 28 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main(){ 9 | int n; 10 | int t; 11 | cin >> n >> t; 12 | int width[n]; 13 | for(int width_i = 0;width_i < n;width_i++){ 14 | cin >> width[width_i]; 15 | } 16 | for(int a0 = 0; a0 < t; a0++){ 17 | int i; 18 | int j; 19 | cin >> i >> j; 20 | cout<<*min_element(width+i,width+j+1)<<"\n"; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /sherlock_and_anagrams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int sherlockAndAnagrams(string s){ 6 | // Complete this function 7 | } 8 | 9 | int main() { 10 | int q; 11 | cin >> q; 12 | for(int a0 = 0; a0 < q; a0++){ 13 | string s; 14 | cin >> s; 15 | int result = sherlockAndAnagrams(s); 16 | cout << result << endl; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /snake_and_ladder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int t; 12 | cin >> t; 13 | while(t--) 14 | { 15 | int n,m; 16 | cin >> n >> m; 17 | 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /string_construction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int stringConstruction(string s) { 6 | // Complete this function 7 | int len=s.size(); 8 | int i=0; 9 | 10 | map visitedCharMap; 11 | 12 | int cost=0; 13 | 14 | for(int i=0;i> q; 30 | for(int a0 = 0; a0 < q; a0++){ 31 | string s; 32 | cin >> s; 33 | int result = stringConstruction(s); 34 | cout << result << endl; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /sum_vs_xor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | long solve(long n) { 5 | // Complete this function 6 | int zeros=0; 7 | long temp=n; 8 | while(temp!=0) 9 | { 10 | if(temp%2==0) 11 | zeros++; 12 | temp/=2; 13 | } 14 | 15 | return pow(2,zeros); 16 | } 17 | 18 | int main() { 19 | long n; 20 | cin >> n; 21 | long result = solve(n); 22 | cout << result << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /super_mancunian.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | int m; 8 | cin >> n >> m; 9 | for(int a0 = 0; a0 < m; a0++){ 10 | int a; 11 | int b; 12 | int w; 13 | cin >> a >> b >> w; 14 | // Write Your Code Here 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /super_reduced_string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | string super_reduced_string(string s) 7 | { 8 | // Complete this function 9 | for(int i=1;i> s; 28 | string result = super_reduced_string(s); 29 | cout << result << endl; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /super_reduced_string.py: -------------------------------------------------------------------------------- 1 | s = raw_input() 2 | stack = [] 3 | for i in xrange(len(s)): 4 | if not stack or s[i] != stack[-1]: 5 | stack += [s[i]] 6 | else: 7 | stack.pop() 8 | if stack: 9 | print ''.join(stack) 10 | else: 11 | print 'Empty String' -------------------------------------------------------------------------------- /tech.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int n; 8 | cin>>n; 9 | for(int i=0;i>s; 13 | unordered_map map; 14 | for(int j=0;j 2 | #include 3 | int main() 4 | { 5 | long q; 6 | std::cin >> q; 7 | long ans[q]; 8 | for(long a0 = 0; a0 < q; a0++) 9 | { 10 | long n; 11 | std::cin>>n; 12 | long arr[n]; 13 | for(long i=0;i>arr[i]; 16 | std::cout<<(1^2); 17 | } 18 | } 19 | // for(long i=0;i