BitWise Operator
Hi All,
I have a question
A country has 25 states ( can vary) and based on population of each state give a color to that state.
for e.g
state1 population is 5000
state2 population is 10000
state3 population is 12000 and so on....
now im also given colors to assign based on population
population==5000 assign green
5000<population<10000 - blue
population==10000 assign orange
10000<population<15000 - yellow and so on up to 100,000 ( this is the max limit of population for a state )
I can give a solution where
Step 1: create a dictionary/hashtable to maintain colors based on population.
Step 2 : Read each country population ( iterate thru countries ) and lookup in hashtable and assign.
the above solution is bruteforce.
I was given a hint to use bitwise operator for this . Any thoughts how I can go about it ?
Thanks,
Sunil,
- burak September 15, 2014Your answer is not brute force. It is essentially linear, bound by the number of states. It is strictly O(2*M+N), but M is already a constant, so it is bound by N.