Skip to main content

Posts

Competitive Programming: Calculate the square of a number without using *, / and pow()

  Hello everyone ...  Here we are going to solve a  Competitive Programming  problem related to  Bit Manipulation. Problem Statement Calculate the square of a number without using *, / and pow() Examples Input : N = 4 Output : 16 Explanation : 4*4 = 16 Constraints 1 ≤ N ≤ 10 8 Expectations Expected Time Complexity:  O(logN) Expected Space Complexity:  O(1) Solution Approach  C++ Code Time Complexity Since we are only iterating through the bits of  N  in its binary representation, this solution's time complexity is  O(LogN) .  Space Complexity Since we are using constant space, this solution's space complexity is  O(1) . Hooray! We successfully solved this problem with the expected time and space complexity. Hopefully, you enjoyed this blog post and learned something new. If you want to share anything or if you have any doubts or suggestions please comment below.  Thank you, guys.  Have a nice day and s tay tuned for new blog posts. Bye ...👋

Competitive Programming: Count total set bits in all numbers from 1 to N

 Hello everyone ...  Here we are going to solve a  Competitive Programming  problem related to  Bit Manipulation. Problem Statement Find the total count of set bits for all numbers from 1 to N (both inclusive). Examples Input : N = 4 Output : 5 Explanation : For numbers from 1 to 4. For 1: 0 0 1 = 1 set bits For 2: 0 1 0 = 1 set bits For 3: 0 1 1 = 2 set bits For 4: 1 0 0 = 1 set bits Therefore, the total set bits is 5. Constraints 1 ≤ N ≤ 10 8 Expectations Expected Time Complexity:  O(logN) Expected Space Complexity:  O(1) Problem Link :  https://practice.geeksforgeeks.org/problems/count-total-set-bits-1587115620/1 Solution Approach  C++ Code Time Complexity Since we are only iterating through the bits of N in its binary representation, this solution's time complexity is  O(LogN) .  Space Complexity Since we are using constant space, this solution's space complexity is  O(1) . Hooray! We successfully solved this problem with the expected time and space complexity.

Competitive Programming: Find the two non-repeating elements

 Hello everyone ...  Here we are going to solve a  Competitive Programming  problem related to  Bit Manipulation. Problem Statement Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other 2 numbers occur exactly once and are distinct . Find the two non-repeating numbers. Examples Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. Input: N = 1 arr[] = {2, 1, 3, 2} Output: 1 3 Explanation: 1 3 occur exactly once. Constraints 1 <= Length of array <= 10 6  1 <= Elements in array <= 5 * 10 6 Expectations Expected Time Complexity:  O(N) Expected Space Complexity:  O(1) Problem Link :  https://practice.geeksforgeeks.org/problems/finding-the-numbers0215/1 Solution The first idea that might come to your mind is to use Sorting and comparing adjacent elements in the sorted array to find the non-repeating elements. This solution's time complexity is O(N*logN) . But we are expecte

Competitive Programming: Count Set Bits in an Integer

Hello everyone ...  Here we are going to solve a Competitive Programming problem related to Bit Manipulation. Problem Statement Given a positive integer N , print count of set bits in it. Examples Input: N = 6 Output: 2 Explanation: Binary representation is '110' So the count of the set bit is 2. Input: 8 Output: 1 Explanation: Binary representation is '1000' So the count of the set bit is 1. Problem Link:  https://practice.geeksforgeeks.org/problems/set-bits0143/1  Solution Approach 1 In this approach, we will loop through all the bits of a given integer and check if the bit is set. If it is, then we will increment the count. To loop through the bits of an integer, we will iterate from LSB (Least Significant Bit) to MSB(Most Significant Bit), i.e, from Right to Left. In each iteration, we will increment the count by 1 if LSB (i.e. last bit) is set and then we will perform the Right Shift operation on the given integer by 1 time. C++ Code Time Complexi

Bug Bounty : Unrestricted File Upload Vulnerability

Hello everyone... Here I'm presenting a writeup on the Unrestricted File Upload vulnerability that I found on a renowned company. Since I should not disclose the real domain, let's say it is  redacted.com This is the first bug that I found and got paid $116 . This is easy to find and I think it took around 15 minutes to find and exploit.  But not all bugs can be found in a short span. There are even days where I didn't find any. But every time I try to hunt on a program I learned something new because I do a lot of googling to understand how applications work.  Moreover, I do bug bounty  part-time for fun. Rewards or bounty that we get in return will boost our interest to do more hunting. All the programs that we can hunt for bugs are like a playground for me to practice what I learned.  Without wasting your time let's get into the writeup. Vulnerability description This bug was found on a domain appsadmin.redacted.com I did subdomain enumeration on  redacted.com   a