Polar_'s blog

By Polar_, history, 2 years ago, In English

I found this on leetcode someone posted the problem . I am wondering if there is a solution for followup .
Given a calculation class where you initialize values for $$$a,b,c$$$ and the following function $$$f(x) = ax^2 + bx + c$$$, and a list of numbers, apply this function to all values in the list.

class Calculation {
int a;
int b;
int c;

int[] calculate(int[] arr)
}

Followup: We want the output array to be sorted. Can we do better than $$$O(nlogn)$$$?

Full text and comments »

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

By Polar_, history, 3 years ago, In English

I think most of Indian cheaters have started to understand that practicing frequently asked problems on Leetcode is lot better than cheating on codeforces or any other similar platform .
Also I can see slowly companies are also realising that hiring based on rating on these platforms would just harm them .
It feels good that codeforces will slowly become cheaters free .
Also kudos to codeforces team for putting so much effort in removing them .
If you are still cheating I would like to know the reason .

Full text and comments »

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

By Polar_, history, 3 years ago, In English

Hey guys !
So I was trying to hack a solution using this test case in Distinct routes.
Problem link .

3 5
1 2
1 2
1 2
2 3
2 3

The answer should be
2
3
1 2 3
3
1 2 3

But I got INVALID INPUT .

I think this input should be valid as per constraints .

Full text and comments »

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

By Polar_, history, 3 years ago, In English

Hi Everyone ! I am not able to understand how to break this problem into subproblems ?
Can someone help please ? Here is the problem link : Problem

Full text and comments »

Tags dp, cses
  • Vote: I like it
  • +2
  • Vote: I do not like it

By Polar_, history, 4 years ago, In English

While reading about max flow from cp algorithm I saw this in the explanation and I really couldn't understand this :(

Here is the image I am attaching
The red line actually shows the reverse direction .
The question is how can we have a flow in reverse direction ? Here is the link to the tutorial

Full text and comments »

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

By Polar_, history, 5 years ago, In English

Hi! I need help in calculating $$$\sum\frac{1}{n^2}\%MOD$$$.
Where $$$MOD$$$ is a prime number .
I know that taking of inverse modulo for every $$$k^2$$$ where $$$ 1 \le k \le n $$$ then adding them up and taking modulo.
But if $$$n$$$ is order of $$$10^9$$$ then how to do it ?
Any faster way to do it ?
Thanks .

Full text and comments »

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

By Polar_, history, 5 years ago, In English

Let's say I have an expression $$$x = k_1\cdot k_2 \cdot \cdot \cdot k_n \% MOD$$$.
Where $$$MOD$$$ is a prime number .
Now I want to divide $$$x$$$ with some $$$k_i\cdot k_j$$$ and I want to mutliply $$$x$$$ with some $$$p$$$ and $$$q$$$ .
Then is it true that $$$x = x{*}MODINV(k_i{*}k_j , MOD -2){*}p{*}q$$$ .

Full text and comments »

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

By Polar_, history, 5 years ago, In English

Today I was trying to solve this problem . But I couldn't solve it . So I tried to understand some solution but still ;( .

Spoiler

I saw this code but couldn't understand . Can anybody help me getting this solution or can you please tell me how to solve this problem .
Thanks ...

Full text and comments »

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

By Polar_, history, 5 years ago, In English

I hava an array of size at max 100000.

I need find all subarrays whose GCD is x .

How can I do it efficiently ? Please help ..

Full text and comments »

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