viralm's blog

By viralm, history, 2 years ago, In English

We want to schedule interviews for N candidates. We have M intervewers who are available for interviewing candidates.

Each candidate and interviewer provides one or more time intervals during which they are available for interviews all for the same day. Find the maximum number of interviews that can be scheduled assuming each interview is 1 hour long.

The interval times are between 0 hours to 24 hours with granularity of 30 minutes. For example, the time intervals: [0, 3], [22.5, 24] are valid intervals but time intervals like: [0.7, 2] are invalid.

N < 1000
M < 1000

Input: Candidate intervals is a list of lists. The inner list is of the format: [start time, end time, candidate id].

Interviewer intervals is a list of lists. The inner list is of the format: [start time, end time, interviewer id]

Output: Single integer denoting the maximum number of interviews that can be scheduled.

Note: We need to schedule at most one interview per candidate. Exactly one candidate and exactly one interviewer participate in an interview.

Full text and comments »

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

By viralm, history, 6 years ago, In English
I am trying to solve a problem where I am given 2 strings A and B. Length of A is n and length of B is m. Now, q queries need to be answered. Each query will consist of 2 integers i and j such that 1 <= i,j <= n. For each such query, I want to find the length of the longest common sub-sequence of A.sub_string(i, j) and B.
Constraints:
1 <= n <= 10^4
1 <= m <= 10^4
1 <= Q <= 10^2

Time Limit: 3 seconds

Full text and comments »

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

By viralm, history, 8 years ago, In English

Often when trying to solve a problem involving Binary Search or 2-Pointer Technique, I make off by one errors, and/or fail to handle edge cases. Even if I know that my solution might fail on a particular edge case, to correct it takes a lot of time. I would like to know a method/implementation, such that I can code up the solutions without having to worry about edge cases, etc. For Binary Search, I know of one such method where to avoid infinite loop, we can use the following code: Say we want to find the maximum index in an array which satisfies certain property -->

while(hi-lo>1)
{
    int mid=(lo+hi)/2;
    int chk=check(mid);
    if(chk==1) lo=mid;
    else hi=mid-1;
}
int ans;
if(check(hi)==1) ans=hi;
else ans=lo;

If any better approach is available(for Binary Search), you are welcome to comment. Also, can you give a good implementation for 2 — Pointer Technique.

Thanks in advance.

Full text and comments »

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

By viralm, history, 8 years ago, In English

How to solve this problem — http://mirror.codeforces.com/problemset/problem/346/B ? I am not able to understand much by reading the editorial. Please Help!!

Full text and comments »

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

By viralm, history, 8 years ago, In English

How to solve the following problem ?


https://code.google.com/codejam/contest/5254486/dashboard#s=p3 Thanks in advance.

Full text and comments »

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

By viralm, history, 8 years ago, In English

How to solve the following problem ?

For any 3 bit strings (consisting only of 1s and 0s) A, B and C, f(A,B,C) is defined as:

f(A,B,C)=(no. of 1s in ((A XOR B) AND C))/(no. of 1s in C).

We are given N bit strings initially. Then we are given Q queries. Each query contains 2 bit strings B and C. For each query output a single bit string A from the initial set of N bit strings, such that f(A,B,C) is minimum.

It is given that the size of all the bit strings given in the input = 2048 (constant).

Input:
   First line contains 2 integers N and Q.
   Then N lines follow, each containing a single bit string of length = 2048.
   Then Q lines follow,
   each containing 2 bit strings B and C each of length = 2048. B and C are space separated.
Output:
   For each query output one line containing the string A and f(A,B,C) (space separated).
Constraints:
   1<=N<=10000
   1<=Q<=10000
   |A|=|B|=|C|=2048 (fixed for all strings)

Example:

   Input:
     2 1
     1001
     1011
     1
     1111 1111
   Output:
     1011 0.25

Eagerly waiting for your replies. Thanks in advance.

Full text and comments »

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