Welcome to the Blog!
Solving Problem: Sum of Multiples
Introduction The sum of multiples of k below n is: Formula: Sk=k⋅m(m+1)2 where m=⌊n−1k⌋. Problem Statement: Find the sum of multiples of 3 or 5 below N. For example: If we list all the natural numbers below that are multiples of 3 or 5, we get 3, 5, 6, and 9. The sum of these multiples is 23. Input…
Solving Problem: Incorrect Regex
(Python) Problem Statement: You are given a string S.Your task is to check whether S is a valid regex. Input Format The first line contains an integer T, the number of test cases.The next T line contains the string S. Constraints 0 < T < 100 Output Format Print “True” or “False” for each test case without quotes. Sample Input Sample Output…
Solving Problem: Combinations
(Python) Problem Statement: You are given a string S.Your task is to print all possible combinations, up to size, of the string in lexicographically sorted order. Input Format A single line containing the string and integer value separated by a space. Constraints 0 < k <= len(S) The string contains only UPPERCASE characters. Output Format Print the…
BFS and DFS
(DSA – Tree Traversal) BFS DFS (Breadth First Search) (Depth First Search) BFS vs DFS: Parameter BFS DFS Full Form Breadth First Search Depth First Search Definition BFS (Breadth First Search) is a graph traversal concept where nodes are traversed on same level before moving to next level. DFS (Depth First Search) is a graph…
Solving Problem: Leap Year
(If-elif-else Control Flow) Problem Statement Check if a year is a leap year. As per the Gregorian calendar (in 1582), the following rule is used to determine the kind of year: The task is to determine if the given year is a leap year or not. Output messages: “Leap year.” if the year is a…
Solving Problem: Symmetric Difference
(Sets) Problem Statement: Given 2 sets of integers M and N, print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either but do not exist in both. Solution: Output: Reference: https://www.hackerrank.com/challenges/symmetric-difference/problem
Solving Problem: Trigonometry
(Python) Problem Statement: ABC is a right triangle, 90° at B.Therefore, ∠ ABC = 90. Point M is the midpoint of the hypotenuse. You are given the lengths AB and BC.Your task is to find ∠MBC (angle θ, as shown in the figure) in degrees. Input Format The first line contains the length of side AB.The second line contains the length of…
Solving Problem: Tax Calculator
(If-elif control flow) Problem Statement: Once upon a time, there was a country inhabited by happy and prosperous people. The people paid taxes, of course – their happiness had limits. The most important tax, called the Personal Income Tax (PIT ), had to be paid yearly and was evaluated using the following rule: Your task is to write…
Solving Problem: Two Sum
(Python) Problem Statement: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example 1: Input: nums = [2,7,11,15], target = 9 Output:…
Bit Manipulation Basics
(Python) Let’s have a quick review of Bit Manipulation techniques in Python. Bitwise Operators Operator Description Example & Bitwise AND a & b ` Bitwise OR a ` b ^ Bitwise XOR a ^ b ~ Bitwise NOT ~a << Left Shift a << n >> Right Shift a >> n Example Program Output: a…
Something went wrong. Please refresh the page and/or try again.
Follow My Blog
Get new content delivered directly to your inbox.
