Home
Gaurav's GitHub Page
Cancel

Kth from End of Linked List (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given the head of a linked list and the number k, Your task is to find the kth node from the end. If k is more than the number of nodes, then the output should be -1. geeksfor...

Swap all odd and even bits (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given an unsigned integer N. The task is to swap all odd bits with even bits. For example, if the given number is 23 (00010111), it should be converted to 43(00101011). Here, e...

Longest Consecutive 1's (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given a number N. Find the length of the longest consecutive 1s in its binary representation. geeksforgeeks SOLUTION APPROACH 1 class Solution{ public static int maxCo...

Party of Couples (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION You are given an integer array arr[] of size n, representing n number of people in a party, each person is denoted by an integer. Couples are represented by the same number ie:...

Rightmost different bit (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given two numbers M and N. The task is to find the position of the rightmost different bit in the binary representation of numbers. If both M and N are the same then return -1 ...

First Set Bit (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given an integer N. The task is to return the position of first set bit found from the right side in the binary representation of the number. Note: If there is no set bit in th...

K-th Bit is Set or Not (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given a number n and a bit number k, check if kth index bit of n is set or not. A bit is called set if it is 1. Position of set bit ‘1’ should be indexed starting with 0 from L...

Power of 2 (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given a non-negative integer n. The task is to check if it is a power of 2. geeksforgeeks SOLUTION The number of set bits should be 1. class Solution { public static b...

Toggle bits in the given range (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given a non-negative number n and two values l and r. The problem is to toggle the bits in the range l to r in the binary representation of n, i.e., to toggle bits from the lth...

Set kth bit (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION Given a number N and a value K. From the right, set the Kth bit in the binary representation of N. The position of Least Significant Bit(or last bit) is 0, the second last bit ...