## Number of bit to be flipped to convert one number to another.

Objective: Given two numbers x and y. write an algorithm to find the number of bits which are to be flipped to convert number x to y. Example x = 10, Y = 20 x...

Skip to content# Tagged: Beginner

## Number of bit to be flipped to convert one number to another.

## Separate even and odd integers in a given array

## Find three elements in an array that sum to a zero.

## Separate 0’s and 1’s in a given array

## Find three elements in an array that sum to a given value

## Majority Element – Part 1

## Check whether the given number is a perfect square

## Check if array is sorted using recursion

## Find the Index from which 0 starts

## Find the increasing OR decreasing point in an array

## Find the only element in array which appears only once

## Algorithm to calculate power(k,n).

## Find remainder without using modulo operator

## Swap two numbers without using extra variable

## Number of 1’s in bit representation of a number

@tutorialhorizon

Objective: Given two numbers x and y. write an algorithm to find the number of bits which are to be flipped to convert number x to y. Example x = 10, Y = 20 x...

Objective: Given an array which contains even and odd integers. Write an algorithm to separate even and odd numbers. Example int [] arrA = {1,2,3,4,6,8,7,12}; Output: [12, 2, 8, 4, 6, 3, 7, 1] Approach:...

Objective: Given an array of integers write an algorithm to find 3 elements that sum to a zero. In short a+b+c = 0. Example int [] = { 3,-1,-7,-4,-5,9,10}; Elements are -4 9 -5 Approach:...

Objective: Given an array which contains only 0’s and 1’s. write an algorithm to separate 0’s and 1’s. Example int [] arrA = {1,0,1,0,1,1,0,0,0,0,1}; Output: [0, 0, 0, 0, 0, 0, 1, 1, 1, 1,...

Objective: Given an array of integer write an algorithm to find 3 elements that sum to a given number k. In short a+b+c = k. Example: int a [] = { 3,1,7,4,5,9,10} , k =...

Objective: Given an array of integer write an algorithm to find the majority element in it (if exist). Majority Element: If an element appears more than n/2 times in array where n is the size...

Objective: Given an integer check whether it is a perfect square. Example: number = 37 Output: false number = 49 Output: true This is fun puzzle which is asked in the interview. Approach: Say number...

Objective: Given an array of integer write a recursive solution to check if array is sorted. Example: int [] a = {1,2,3,4}; Output: true int [] a = {1,2,3,4,2}; Output: false Approach: This problem can...

Objective: Given an array of integer which 1’s followed by 0’s. Find the starting index of 0. Example: int [] a = {1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0}; First Index from where 0 starts: 10 int [] a = {1,1,1}; ...

Objective: Given an array of integer which is first increasing then decreasing. Find the element in array from which point it starts decreasing. OR Given an array of integer which is first increasing then decreasing....

Objective: Given an array of integers, all the elements are appear twice but one element which appears only once. Write an algorithm to find that element. Example: int [] a = { 1,5,6,2,1,6,4,3,2,5,3}; output:...

Objective: Given two numbers ‘k’ and ‘n’. Write an algorithm to calculate kn. Example: k = 4, n = 5 kn = 45 = 1024 k = 2, n = 3 kn = 23 =...

Objective: Write Given two integers ‘number’ and ‘divisor’, Write an algorithm to find the remainder if ‘number’ is divided by ‘divisor’. Condition: You are not allowed to use modulo or % operator. Example: num =...

Objective: Write an algorithm to swap two numbers without using extra variable. This is fun puzzle which is asked in the interview. Approach: Example: a = 3, b = 5 a = a + b...

Objective: Write an algorithm to count the number of 1’s in the bit representation in given number. Example: Number: 6 Output: 2 ( 1 1 0) Number: 11 Output: 3 ( 1 0 1 1)...

%d bloggers like this: