Sandesh
BAN USERThis is not O(log). You are blindly dividing an array until you get to the difference one ... thus checking every possible i,j (where ij =1) ... Asymptotically it is O(n)
I think interviewer is looking for O(m*log n) answer i.e. for every missing number it should be log(n) operations.
I used the standard swapping and recursion permutation algorithm.
If you don't know that, First of all check how to calculate permutations.
#include <iostream>
using namespace std;
void avoidCapitalPermutation(string& str, int k, int n)
{
if(k==n)
cout << str << endl;
if(isupper(str[k]))
{
avoidCapitalPermutation(str,k+1,n);
}
else
{
for(int i=k;i<=n;i++)
{
if(!isupper(str[i]))
{
swap(str[i],str[k]);
avoidCapitalPermutation(str,k+1,n);
swap(str[i],str[k]);
}
}
}
}
int main()
{
string str = "AbCdEf" ;
avoidCapitalPermutation(str,0,str.length()1);
return 0;
}
o/p
AbCdEf
AbCfEd
AdCbEf
AdCfEb
AfCdEb
AfCbEd

Sandesh
December 26, 2013
Repvivekwebediting, IC3 at Bazaarvoice
Mantra to break boyfriend's marriage is the best and the most effective mantra. If you interested in this mantra ...
RepRhondaPBenedict, SEO at IITD
Mantra to break boyfriend's marriage is the best and the most effective mantra. If you interested in this mantra ...
Repperryks, xyz at AMD
Perry is a good awarded astrologer. she have such a good experience of solving people problems very well. people was ...
Open Chat in New Window
 Sandesh December 19, 2014