rahul_1234's blog

By rahul_1234, history, 7 years ago, In English

Given a 2D board and a word, find if the word exists in the grid.

The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The cell itself does not count as an adjacent cell. The same letter cell may be used more than once.

1). Grid: ab

Word = abab

return 0

2). Grid

[ ["ABCE"],

["SFCS"],

["ADEE"] ]

Word = "ABCCED"

return 1

I cannot get a proper solution to this which handle all cases so if someone can help, it would be very helpful?

Full text and comments »

  • Vote: I like it
  • +14
  • Vote: I do not like it

By rahul_1234, history, 7 years ago, In English

Given 'n' circles (each defined by center and radius) Write an algorithm to detect if given circles intersect with any other circles in the same plane

Better than O(n^2) complexity

Full text and comments »

  • Vote: I like it
  • +16
  • Vote: I do not like it

By rahul_1234, history, 7 years ago, In English

Giving a string and an string dictionary, find the longest string in dictionary which can formed by deleting some characters of the giving string.

Example:

S = abpcplea,

Dict = {ale, apple, monkey, plea},

the return "apple"

Can somebody provide trie solution( O(N*K) ), N: length of string, K: length of longest word?

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By rahul_1234, history, 7 years ago, In English

In today's kickstart problem, https://codejam.withgoogle.com/codejam/contest/6304486/dashboard#s=p1

I am getting wrong answer on big input but smaller input works fine and gives correct answer. Here is my code: https://ideone.com/7Ffer4

I tried with bigger input and answer is coming mostly as 0.

I can't find the error. Can someone tell the error and how to correct it.

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By rahul_1234, history, 8 years ago, In English

Hi, I wanted to solve this question in O(N) but couldn't think of it. I did it in O(N logN ) using priority queue but can somebody provide me O(N) solution.

https://postimg.org/image/c31iexg13/

The link of question is not opening now, so I have shared the pic of question.

Full text and comments »

  • Vote: I like it
  • -15
  • Vote: I do not like it

By rahul_1234, history, 8 years ago, In English

Can anybodyt help to find complexity oof this algo: T(n) = n^ (1/3) T( sqrt( n) ) + 2n

I solved it and found it be O(n) but is it correct? Please confirm.

Full text and comments »

  • Vote: I like it
  • +20
  • Vote: I do not like it

By rahul_1234, history, 8 years ago, In English

Given an array A of n numbers, we want to select a sub-sequence of A such that each number in the sub-sequence is at least as large as the previous one, and such that the length of this sub-sequence is as large as possible. Give a divide-and-conquer algorithm for this problem. What is the running time of your algorithm?

I got this explanation but could not understand:

A natural algorithm is to divide the problem into n problems of size n/2, where for problems on the left, we compute the longest increasing subsequence ending at a given position, for the ones on the right we want to compute the longest increasing subsequence with a given element as the smallest. The recursion is therefore T(n) = nT(n/2) + O(1).

So please explain this to me. I'll be thankful to you.

Full text and comments »

  • Vote: I like it
  • -12
  • Vote: I do not like it

By rahul_1234, history, 8 years ago, In English

I want to sort the numbers using linked list in O(nlogn) time complexity and O(1) space complexity? Plz help me in this.

Full text and comments »

  • Vote: I like it
  • -14
  • Vote: I do not like it

By rahul_1234, history, 8 years ago, In English

In the problem https://www.codechef.com/problems/CHEFQUE,

submission : https://ideone.com/l2LPvy got TLE. It used comp().

However, when I didn't use comp() and just used sort( vc.begin(), vc.end() ) it got accepted. Submission link https://ideone.com/NgbwUO.

Even though both are doing same thing, why comp() is giving TLE and how can we improve on it. Please somebody guide me on this.

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By rahul_1234, 9 years ago, In English

For code: plz explain the output. I can't get how Test1 t1 = new Test1(10); is getting executed despite not in constructor.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By rahul_1234, history, 9 years ago, In English

In C++, for comparing doubles we do:

bool AreSame(double a, double b) { return fabs(a — b) < epsilon; } // epsilon : 0.000000001

However in java to compare Bigdecimal properly would this suffice:

if(r.compareTo(BigDecimal.ZERO) == 0) { System.out.print("Yes"); }

Or we have to do something else. Can somebody elaborate on this.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By rahul_1234, history, 9 years ago, In English

In C++, for comparing doubles we do:

bool AreSame(double a, double b) { return std::fabs(a — b) < std::numeric_limits::epsilon(); }

However in java to compare Bigdecimal properly would this suffice:

if(r.compareTo(BigDecimal.ZERO) == 0) { System.out.print("Yes"); }

Or we have to do something else. Can somebody elaborate on this.

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

By rahul_1234, history, 9 years ago, In English

Can someone explain me the macro:

#define tr(c,it) for( typeof(c.begin()) it=c.begin(); it!=c.end(); ++it )

Plz stress on use of typeof and why this macro can be used for all the containers.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it