An Enthusiast
BAN USER
Use a hash table with count of the character as value in key value pair.. keep on increasing value as u find the same char. Also, maintain a max_counter and max_char
Time Complexity O(n), Space Complexity O(n) .. n = number of characters in string
I dont think its possible in less than O(n) as we have to traverse all the characters of string at least once
- An Enthusiast April 23, 2014Big Data Analysis using platforms like Hadoop
- An Enthusiast April 21, 2014+1 you got it all right :)
- An Enthusiast April 18, 2014There are many ways to solve this problem, below is my attempt
int rand7()
{
int k = rand5() + rand5() + rand5() + rand5() + rand5() + rand5() + rand5();
return k % 7;
}
Correct me if I am wrong but is this even possible to achieve. I tried placing 2 queens on 2X2 but no equilibrium, I tried placing 3 queens on 3X3 board still no equilibrium, I tried few other combinations where M was less than 15 for a MXM board but no equilibrium. If someone understands this problem correctly please present an example. Thanks!
- An Enthusiast April 16, 2014When a Web page is blank, there are a few likely reasons. The reasons fall into three categories: 1, a server-related problem; 2, a network problem; and 3, a client browser or computer problem.
1) Server Problems
The page could have been intentionally left blank. It may have a failed redirect script attached to it, or the creator of the site may be in the process of redesigning it.
2) Network Problems
A network error can result in partial content delivery. In such a case, you might be able to solve the problem by pressing reload/refresh or "F5."
The Domain Name System (DNS) cache may be displaying an old page that has already been changed on the server. This sometimes occurs when the site has been moved to a new server.
3) Client Browser or Computer Problems
If other websites fail in the same browser, it might have a configuration issue. The URL for the website may be incorrect.
The browser may have cached an old copy of the page. Clear the browser's cache to see if an updated version of the site will appear. The website may not work correctly with the browser. Try another browser to see if it works.
I would attempt something like this
Let's assume Initially both A and B are null sets A = {} and B = {}
1) Create 3 data structures Hash Table, List_Union, List_Intersection
2) Whenever u get a new number in A or B add it to the hash table
2a) if the number already exists in hash table, add the number to List_union
2b) If number does not exist in hash table, add it to hash table and add that number to List_Intersection
3) you can maintain these 3 data structures and whenever u have to find the A-B or B-A just do AUnionB - AIntersectionB
Does the new list has to be sorted as well ? Can u give an example ?
- An Enthusiast April 05, 2014Here is code in C#.. I have used uint to make sure N is not negative as square can never be negative. Also if N is 0 return false
private static bool isSquare(uint N)
{
if (N == 0)
{
return false;
}
for (int i = 1; i * i <= N; i++)
{
if (i * i == N)
{
return true;
}
}
return false;
}
makes sense.. also first time u find a char break the loop and return false
- An Enthusiast April 03, 2014First number of a phone number can not be 0. Just saying
- An Enthusiast March 25, 2014one has to get rid of last
if(flag==1) break;
to get all possible set of indexes.
- An Enthusiast November 14, 2013did u even read the quest
- An Enthusiast November 14, 2013I wish you had used more comments on your code :/
- An Enthusiast November 14, 2013#include <stdio.h>
void check(int,int);
int main()
{
int a,b;
printf("this program works only for positive integers \n");
printf("enter expected passwd \n");
scanf("%d",&a);
printf("enter input passwd \n");
scanf("%d",&b);
check(a,b);
return 0;
}
void check(int op, int ip)
{
int flag_digit = 0;
int k1,k2,k3;
int faulty_digit;
while(op){
k1 = op%10;
k2 = ip%10;
k3 = 1;
if(k1==k2){
op = op/10;
ip = ip/10;
}
else{
if(!flag_digit){
faulty_digit = k1;
flag_digit++;
op=op/10;
k3++;
}
if(faulty_digit != k1){
printf("Incorrect password \n");
break;
}
if(faulty_digit == k1 && (k3 ==1)){
op = op/10;
}
}
}
it was a week back so this is all i could remember :/
- An Enthusiast February 04, 2013
We can also do it by maintaining a prev pointer taking care of the insertion at head.. below is an idea ..
- An Enthusiast May 12, 2014