# Tag: Tricky

## Calculate frequency of all elements present in an array of specified range in linear time and using constant space

Given an unsorted array of integers whose each element lies in range 0 to n-1 where n is the size of the array, calculate the frequency of all elements present in the array in linear time and using constant space.   Get great deals at Amazon

## Print all distinct Subsets of a given Set

Given a set S, generate all distinct subsets of it i.e., find distinct power set of set S. A power set of any set S is the set of all subsets of S, including the empty set and S itself.

## Set both elements of a binary array to 0 in single line

Given an binary array of size two having alteast one element as zero, write a single line function to set both its elements to zero. Use of ternary operator and direct assignment of elements are not allowed.

## Rearrange array such that A[A[i]] is set to i for every element A[i]

Given an unsorted array of integers whose each element lies in range 0 to n-1 where n is the size of the array, rearrange array such that A[A[i]] is set to i for every element A[i] in the array. Do this in linear time and without using any extra constant space.

## Generate numbers from 1 to 7 with equal probability using specified function

Write an algorithm to generate numbers from 1 to 7 with equal probability using a specified function which produces random numbers between 1 to 5 with equal probability.

## Implement Ternary Operator Without Using Conditional Expressions

In this post, we will see how to implement ternary-like operator in C without using conditional expressions like ternary operator, if–else expression or switch-case statements.

## Find if a number is even or odd without using any conditional statement

Given a number, find out if it is even or odd without using any conditional statement (if-else) or ternary operator.

## Determine if two integers are equal without using comparison and arithmetic operators

In this post, we will discuss how to determine if two integers are equal without using comparison operators (==, !=, < , >, < =, >=) & arithmetic operators (+, -, *, /, %).

## Generate Desired Random Numbers With Equal Probability

Write an algorithm to generate random numbers from 1 to 12 with equal probability using a given function which generates random numbers from 1 to 6 with equal probability.

## Single line expressions to swap two integers in Java

Given two integers, swap them in single line in Java.     There are many expressions to swap two variables in single line in Java. Notice that all below methods can also be used with C/C++.   1. Using Bitwise XOR(^) Operator