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

Автор rajkumar62506, история, 3 года назад, По-английски

Hello Coders, Please checkout video to see solution for problem 1 and 2 of Trilogy Innovations(CodeNation) 15th May 2022 Test. Problems were very nice to solve.

Video Link — https://youtu.be/phE4EL41rC8

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

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

Автор rajkumar62506, история, 3 года назад, По-английски

Hello Coders, Recently In online test of BNY company these two questions were asked. It will be great if someone can give approach to solve these questions.

  1. Given two arrays of integer A and B of length n. We have to choose k indexes such that min(Sum of elements of A at chosen indexes, sum of elements of B at chosen indexes) is maximized. We have to return that maximum sum.

1<=A[i],B[i],n<=50

1<=k<=n

  1. Given integer array A of length n. Initially our power will be 0. Now in one operation we can choose two indexes i and j, i != j. Now we can add A[i] ^ A[j] to power and have to remove any one element. So after n — 1 operation we will be left with only 1 element. At that point we have to stop the process. We have to return what is the maximum power we can collect.

1 <= n <= 1000

1 <= A[i] <= 10^9

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

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

Автор rajkumar62506, история, 4 года назад, По-английски

Hello, Can anyone provide hint to solve below problem on segment tree.

Problem Link:Problem Link

Problem Description:

A city is a sequence of n cells numbered from 0 to n−1. Initially, all cells are empty. Then m events of one of two types occur sequentially:

a building with the strength h is being constructed in the cell i (if the building already existed in this cell, it is demolished and replaced with a new one),

in the interval from l to r−1 an earthquake of power p happens, it destroys all buildings whose strength is not more than p. Your task is for each earthquake to say how many buildings it will destroy.

Input

The first line contains the numbers n and m, the number of cells and the number of events (1≤n,m≤105). The following m lines describe events. The description of each event is as follows:

1 i h: a building with the strength h is constructed in the cell i (0≤i<n, 1≤h≤10^9).

2 l r p: an earthquake of power p happens on a segment from l to r−1 (0≤l<r≤n, 0≤p≤10^9).

Output

For each event of the second type, print how many buildings were destroyed.

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

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

Автор rajkumar62506, история, 4 года назад, По-английски

Hello, Can anyone explain idea to solve E. Lucky Array problem. I tried to understand from editorial but I'm finding difficult to understand. Problem Link:E. Lucky Array

Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya has an array consisting of n numbers. He wants to perform m operations of two types:

add l r d — add an integer d to all elements whose indexes belong to the interval from l to r, inclusive (1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ 10^4);

count l r — find and print on the screen how many lucky numbers there are among elements with indexes that belong to the interval from l to r inclusive (1 ≤ l ≤ r ≤ n).

Each lucky number should be counted as many times as it appears in the interval. Petya has a list of all operations. The operations are such that after all additions the array won't have numbers that would exceed 10^4. Help Petya write a program that would perform these operations.

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

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

Автор rajkumar62506, история, 4 года назад, По-английски

Hello, Is it possible to do range add query in segment tree for XOR queries as we can do for sum queries. I am not finding way to do it. Because for range add for sum, we can update parent node and push update for child so we can use lazy propagation. But for range add for XOR queries how can we update parent node without updating child nodes?

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

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

Автор rajkumar62506, история, 4 года назад, По-английски

Hii Coders, Recently I gave NCR Campus Codewar Test on Hackerearth. Has anyone get any update about shortlist?

Also in Hackerrank it is showing "Not Participated", why?

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

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

Автор rajkumar62506, история, 4 года назад, По-английски

Hello Everyone,

There are many solutions for LCA query,like simple O(N) by traversal only,O(log(N)^2) using Binary lifting + Binary Search,Also most famous O(log(N)) solution. But recently I when I was learning about sparse table, I accounted with O(1) sol for each query using Euler Tour+RMQ using Sparse table. I tried to submit sol using this on SPOJ and CSES problem set and got accepted.

SPOJ Submission
CSES Submission

Now I have only one doubt that is this O(1) solution has any flaw?

If yes,what?

And if not,as far as I know this sol is not so famous compared to log(N) sol,why? even it is easy to code.It might possible that it is famous but I didn't know that.

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

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

Автор rajkumar62506, история, 4 года назад, По-английски

Hello Coders, Suppose I have string s and I'm creating new string s1 by s1=s[j--]+s1 where j is initially (j=s.length()-1). Is this operation in C++ is time costly.

Because I was solving D2. Prefix-Suffix Palindrome (Hard version) problem.In this problem we are given string s,and we need to find string t,which satisfy given condition.

1)The length of t does not exceed the length of s.

2)t is a palindrome.

3)There exists two strings a and b (possibly empty), such that t=a+b ( "+" represents concatenation), and a is prefix of s while b is suffix of s.

I tried to solve it in following way,

1)string s1=s2="" and i=0,j=s.length()-1, now till s[i]==s[j],I added elements to s1 and s2; ie. s1+=s[i++],s2=s[j--]+s2;

2)after first step whatever string remains unused,I found longest prefix and suffix palindrome using manachers alg,and choosen max of them.

Now Main point is that when I submitted it was giving TLE on testcase 13. then I just tried to change s2=s[j--]+s2 by just only finding s1 and s2 will be obviously reverse of s1. And my code gets Accepted.

So my question is how can s2=s[j--]+s2 can be reason for TLE?

sol having TLE.

Accepted sol.

Both sols only differ in way I calculated s2.

UP1: I don't know what's wrong with some people, I have seen many comments in announcement or in tutorial section that's are either funny or sarcastic or memes ,and they gets many upvotes,I'm not saying that should not be upvoted,in fact If I like,I also upvotes them.But when some one ask for doubt most of the time it gets downvoted. IDK why?

I think many people started taking it in wrong way, they think that If they didn't like post or comment then it should be downvoted.But what is meaning of contribution? If someone if contributing to community then he should get +ve contribution and If he is spreading negativity,he should be downvoted.

But when someone ask doubt then surely he is not harming community, also he is not contributing to community either because he asked doubt for himself and it may not be useful to all people.So when someone ask doubt,two things possible either his doubts may not be useful to someone or someone having similar doubt can solve it by reading comments by others. Then how it is harming community that many are downvoting. If they thinks it is not useful they can just ignore it,what's reason for downvote.

I just tried to said what I felt after seeing downvotes on my this blog and others blogs asking for doubts,May be I will be downvoted for saying this.

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

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

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

Hello! In my submission 80851257 to the problem E. Graph Coloring I'm getting RUNTIME_ERROR with Exit Code -1073741819. I don't know what's wrong with my code? I tried in my IDE it's working fine, Also I run same code on online IDE:Can see here and it's running fine but it is giving RUNTIME_ERROR on CF.Can Anyone Explain?

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

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