Блог пользователя rahul_1234

Автор rahul_1234, история, 8 лет назад, По-английски

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?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

Автор rahul_1234, история, 8 лет назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • +16
  • Проголосовать: не нравится

Автор rahul_1234, история, 8 лет назад, По-английски

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?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

Автор rahul_1234, история, 8 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

Автор rahul_1234, история, 8 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -15
  • Проголосовать: не нравится

Автор rahul_1234, история, 9 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +20
  • Проголосовать: не нравится

Автор rahul_1234, история, 9 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -12
  • Проголосовать: не нравится

Автор rahul_1234, история, 9 лет назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • -14
  • Проголосовать: не нравится

Автор rahul_1234, история, 9 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

Автор rahul_1234, 9 лет назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

Автор rahul_1234, история, 9 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

Автор rahul_1234, история, 9 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

Автор rahul_1234, история, 9 лет назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится