prashaenator
BAN USER
- 0of 0 votes
AnswersGiven an array { -2 3 5 0 -3 7 -1}. Sort the array in such a way that array should contain -ve numbers first and then zero and then all +ve numbers. (Note: order of +ve number and order of -ve numbers should be same after sorting). For ex: the o/p of above array is {-2 -3 -1 0 3 5 7}
- prashaenator in India for BING| Report Duplicate | Flag | PURGE
Microsoft Developer Program Engineer Algorithm
We need to store 4 things
1. color
2. presence
3. type of the coin
4. location
Locations range is (0,0) = 0x00 to (7,7) = 0x77 which need 6bits. That means 32 * 6bits = 24bytes (for storing the locations)
1 bit for color => 32 bits = 4 bytes
1 bit for presence => 32 bits = 4 bytes
3 bits for type of coin (000 - pawn, 001 - bishop, 010 - knight , 011 -rook, 100- queen, 101 - king) => 3*32 = 12 bytes
Total = 44 bytes
@ Srinivas: Yes, I do agree. max sum is -2, min sum is -10. But, does this algo give right answer ?
- prashaenator August 17, 2012@ karthikaditya
Your code doesn't seem to work if the array contains all -ve numbers
Ex : {-4 , -4 , -2}
Max Sum is -10... But, your algo give 0 as max sum
@arya
How does it work if the array contains all the negative numbers
for ex : { -4, -5, -2}
Max sum should be -11
Open Chat in New Window
This problem can be solved using prime numbers
- prashaenator August 18, 2012Let's say A is an array which contains first 10 prime numbers
A = { 2,3,5,7,11,13,17,19,23,29}
unsigned long int multnum =1, multsearchnum =1 ;
foreach digit of number
{
multnum *= A[digit];
}
foreach digit of (searchNumber)
{
multsearchnum *= A[digit];
}
if { multnum % multsearchnum == 0} {
print ( "all digits of search string are present in the number");
}
I didn't find any failing case till now. Please let me know if you find any failing case.