clearly the prob. of getting true|false and false|true are equal to
0.6*0.4. Therefore the following code works,
bool uniform(){
bool f1;
bool f2;
do{
f1 = non_uniform();
f2 = non_uniform();
}while(!(f1 ^ f2));
return f1;
}
On Mar 17, 10:24 am, saurabh agrawal wro
BFS search the maze
On Mar 2, 11:26 am, Don wrote:
> class coord
> {
> public:
> int x;
> int y;
>
> };
>
> class SolveMaze
> {
> public:
> SolveMaze() { location.x = location.y = 0; }
> bool Explore();
> private:
> list visited;
> coord location;
>
> };
>
> bool Explore()
> {
> //
More comments on Ashish's approach. When implementing, you could
reverse the list when you see it's in descending order. Then merge
would be easier.
On Mar 3, 1:03 am, Ashish Goel wrote:
> find two consecutive sequences(can be two increasing2I, 1i1d,1d1i,2D), merge
> them and then merge every nex
for numbers from 0 to n, if you count the numbers whose LSB is 0 vs.
those has 1, if count(0) > count(1), the missing number's LSB is 1,
otherwise it's 0. Continue for the second LSB, your can find the
missing number bitwise.
On Mar 1, 3:14 pm, bittu wrote:
> An array A[1...n] contains all the in
@gaurav. They way I see it it's O(nlogn)?
you have n/4 for each level of the recursion tree and logn height. In
total its O(nlogn)
On Feb 28, 9:27 pm, Vinay Pandey wrote:
> Hi,
>
> Here is my solution, let me know:
>
> /* a helper function */
> void swap(int* arr, int index1, int index2) {
> /
DFS would work I think, if you try to find shortest path, use BFS
On Mar 1, 3:30 pm, bittu wrote:
> Imagine a robot sitting on the upper left hand corner of an NxN grid.
> The robot can only move in two directions: right and down. How many
> possible paths are there for the robot?
>
> FOLLOW UP
>
@ankit How do store the maximum? I know you mark the last element in
the heap invalid. But for the case above, first 80 was extracted and
then 60 should be extracted. But 60 would still lie in the first
array.
On Feb 25, 6:10 am, ankit sambyal wrote:
> Hey, it can be done in o(n*logn) time by ca
Using Dynamic programming.
Divide array into two parts a and b. Run the minimum edit distance
solution for each pair of (a,b)(except this time for b we need to
start from the end of the array). Find the minimum among those.
On Feb 24, 10:41 am, sukhmeet singh wrote:
> How do Levenshtein distanc
Are you talking about IPC?
On Feb 22, 10:05 am, jaladhi dave wrote:
> What do you mean by data element here ? Also by file you mean the file where
> you wrote the code ? And above all which programming language are we talking
> ?
>
> You hit send button too early I guess :)
>
> On 22-Feb-2011 7:
use a tree. For the first N lines, build a tree accordingly. For the
next M lines search the tree. If miss, bump up the counter and add
the node.
On Feb 17, 7:53 am, Akshata Sharma wrote:
> On Unix computers, data is stored in directories. There is one root
> directory, and this might have seve
Divide records into parts that could fit into main memory. Do rank
find algorithm for certain range if necessary.
On Feb 16, 7:26 pm, bittu wrote:
> given a very large file (millions of record), find the 10 largest
> numbers from it.in minimum time complexity
> Don't think about hashing . Again I
Greedy, always choose the remaining one that is the lexicographically
smallest since choose any other way will yield a lexicographically
greater one.
void concante(char **strings, int n){
qsort(strings,n,sizeof(char *),compareStr);
}
int compareStr(const void *a, const void *b){
return
Nice solution. Similarly you could #define:
void change()
{
#define change() i=10
}
On Feb 16, 12:55 pm, ankit sablok wrote:
> nice solution
>
> On Feb 15, 11:22 pm, jagannath prasad das wrote:
>
>
>
>
>
>
>
> > void change()
> > {
> > #define i i=10,n}
>
> > this will do..
>
> > On Tue, F
since it is guaranteed that l points to the start of the character.
Thus I would refer to 'X‘ as the byte l points to. Each number in the
following represents the MSB of the corresponding byte. E.g. 101X -->
the byte preceding X has MSB 1 and the byte preceding that has MSB 0
the byte preceding tha
hash would be a perfect choice.
I make a MinMaxHash class which would keep track of the min and max
value of the key.(since in this case we would never remove a key, thus
this primitive approach works. Otherwise use treeMap)
class MinMaxHash extends HashMap{
private Integer min = Integer.MAX_
@Abhijit. Does your code takes O(N^2)? I think the following code
would do it in O(N)
iterate the string once:
void remove(char *a){
if(!a){
int i = 0, j = 1;
while(a[j]!='\0'){
if(i<0 || a[i]!=a[j]){
I agree time should be O(kn)
On Jan 26, 9:55 pm, Sharath Channahalli
wrote:
> a) Find the median - O(n)
> b) remove the element and again find the median
> c) conitnue b until you get k-1 elements
>
> time complexity - kO(n)
>
> On Wed, Jan 26, 2011 at 9:55 PM, ritu wrote:
>
> > solution is nice
call it by reference.
bst *rec = Null;
insert(rec,5);
void insert(bst *&rec,int data){rec->data = data;}
Or declare it as
void insert(bst **rec,int data){*rec->data = data;}
and invoke with insert(&rec,5);
First one is just syntactic sugar to me although you can argue about
the whole pass-by-va
@Wei Please test you code on "cdbbcbbca". I believe it outputs 2
instead of 8.
On Jan 14, 4:09 am, "Wei.QI" wrote:
> FindStartIndex(char[] a)
> {
> int start = 0;
> int current = 1;
> while(current < a.Length)
> {
> if(a[current] < a[start])
> {
> start
; > > At each location if the value is k ,
> > > find the largest value in the next k elements and jump there.
>
> > > This greedy approach works in 0(n^2) and i believe it works. If not can
> > > someone give me a counter example ?
>
> > > On Sat,
@Avi Greedy approach doesn't work since you can't ensure the choice is
locally optimum. Consider 3,9,2,1,8,3. Using greedy alg. would give
you 3,1,8,3 while otherwise DP would give you 3,9,3.
On Jan 14, 6:11 am, Avi Dullu wrote:
> I guess u got confused with the comment I wrote, I have added 2 p
It's irrelevant but Building Special Tree has the same acronyms as
Binary Search Tree...lame joke I know
On Jan 14, 8:44 am, vaibhav agrawal wrote:
> If it is a BST...then having a pre-order traversal can give us the unique
> binary tree.
>
> Also, as per the problem statement,
>
> > every node c
Bayes' theorem: http://en.wikipedia.org/wiki/Bayes'_theorem
P(x=even|x>3) = P(x>3|x=even)*P(x=even)/P(x>3)===>B
On Jan 14, 2:29 am, snehal jain wrote:
> An unbalanced dice (with 6 faces, numbered from 1 to 6) is thrown. The
> probability that the face value is odd is 90% of the probability that
>
if you meant starting the leftmost 1, to check if its palindrome:
unsigned int o = v;
unsigned int r;
for (r = 0; v; v >>= 1)
{
r <<= 1;
r |= v & 1;
}
if (o == r)
printf("palindrome\n");
else
sort on two keys, primary key is frequency, secondary key is
occurrence.
using namespace std;
struct Item{
int freq;
int occur;
char chr;
Item(){ freq = 0; occur = -1; chr = -1;};
};
bool sortItem(const Item a, const Item b){
if(a.freq != 0 && b.freq != 0){
@snehal
1. Both are valid.
2. see taocp's sol.
The probability of selecting AB to shoot is 1/3, so is BC,AC
If AB were selected, the probability of hitting the target is (1-
probability of both of them missed) = (1-(1-P(A)(1-P(B)),
similar with case BC and AC.
On Jan 11, 11:58 am, snehal jain wro
implemented it based on juver++ & zhang. I think both stacks need to
provide get_min functionality...
class MyQueue{
private ItemStack pushstack;
private ItemStack popstack;
class Item{
int val;
int min;
public Item(int val,int min){
brute force approach
On Jan 12, 5:42 am, AKS wrote:
> can someone just expain the plain simple logic used to solve this
> problem ??
> Cdn't get it seeing the code
>
> On Jan 11, 10:08 pm, Jammy wrote:
>
>
>
>
>
>
>
> > There are apparently m
I think you meant n^3*log(K).
Multiplication on two matrices would take O(n) per entry. And total
#entries is n*n, thus multiplying 2 matrices takes O(n^3)
To get a^(K), use simple divide-and-conquer technique. Since once one
gets a^(K/2), to get a^(K) only needs to square it.
Now we get T(K) = T(K
ou, output will be :
> (John)1 4 5 6 2 2 - (Mary)2 2 4 5 6 1 --- (john) 1 7 8 -- (Mary) 8 1
> 7
> minimum cuts = 3
>
>
>
> On Tue, Jan 11, 2011 at 8:38 PM, Jammy wrote:
> > @Arpit Please explain your solution to me. As far as I understand,
> > every alte
@Arpit Please explain your solution to me. As far as I understand,
every alternate of two person should sum up equally. Which means
every pair of (john, mary) has the same sum for john and mary.
On Jan 11, 2:55 am, Arpit Sood wrote:
> @jammy your code isnt working for the mentioned test c
(a) it is intuitive to see we need to make a recursive function which
takes the following arguments:
1) array,
2) start index,
3) length of the array,
4) a sentinel indicating if it is the first half or second half
5) a sum if it is the second half
6) number of cuts so far
I guess it has to do with how float/double is stored on your computer.
Always use an error tolerance when it comes to floating-point numbers
comparison. By the way, on my machine it outputs the same
thing("Hello")
e.g.
#define epsilon 10e-6
if(275.7-a>epsilon)
printf("HI");
else
printf("Hello"
I wondered that too...seems kid 3 gets too many wishes
On Jan 8, 8:21 pm, bhawana goel wrote:
> In the 3rd test case, how come the answer is Yes. 1,2 and 3 are
> forming a cycle.
>
> On Jan 8, 1:19 pm, juver++ wrote:
>
>
>
>
>
>
>
> > Also, you may use hash_set and hash_map if such exists in you
34 matches
Mail list logo