algorithms400's blog

By algorithms400, 5 years ago, In English

Initially, I have given empty list. I have given Q queries, each queries can perform two types of operation on this list as :

1 x y : Insert value x, y times in list.

2 k : Print kth element of sorted list.

Constraints:

1<= Q <= 2*100000

1<= x,y <= 10^9

At any query, k is always less than or equal to list size.

List can have maximum 10^5 different values.

I have tried to solve this using set of pairs, but for each print it takes O(n) time in worst case.

Please, helps in figure out to solve these operation in O(n*log n ) where n stands for maximum size of list.

Full text and comments »

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

By algorithms400, history, 6 years ago, In English

How to find the numbers of ways to fill a grid (3*n)array, with three colors A, B and C.

Under the following constraints:

1) All the n cells of the same row can't have the same color.

2) All the 3 cells of the same column can't have the same color.

Sample input : if n=2, then output or number of ways = 174.

Please explain the approach for this.

Full text and comments »

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