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 i-j =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
Repvivekwebediting, IC3 at Bazaarvoice
Mantra to break boyfriend's marriage is the best and the most effective mantra. If you interested in this mantra ...
Repdawnmhodges111, abc at 247quickbookshelp
Hello I am a Web writer. All my studies complete from california.my hobby is write different type article.Right ...
RepRhondaPBenedict, SEO at IIT-D
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 ...
RepBrezaLoni, Health inspector at Chess King
I am Health inspector from Memphis, USA .My work involves inspecting restaurants, schools, public pools, nursing homes, and daycare centres ...
RepEileenWenda, DIGITAL MARKETING at Accenture
I am Eileen , a football Referee skilled at maintaining a safe environment for both players and observers, inspecting the playing ...
- Sandesh December 19, 2014