codinghermit05's blog

By codinghermit05, history, 7 weeks ago, In English

Trying to implement the system design of Uber where I am allowed to add new locations and new routes to those locations anywhere in the map. How can I optimize my Dijkstra algorithm so that I don't have to run it for all the nodes everytime I add a new edge or node to my graph (map).

Read more »

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

By codinghermit05, 2 months ago, In English

Recently I got to know about this O(n) solution for longest palindromic substring and am stunned by the working of the algorithm. How could an algorithm work better than a grid DP solution?! Would be nice if anyone could break down the algorithm for me. Also looking forward to know about more such daring algorithms that can beat the crap out of the traditional dynamic programming solutions. Thank you.

Read more »

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

By codinghermit05, 3 months ago, In English

Submissions to some old problems (without clear editorials or solutions) are greyed out. How can I know the solution to such problems in Codeforces?

The problem I am trying to learn: https://codeforces.com/gym/102760/problem/F

Words on Editorial: "There is another, more difficult solution. If you know how to find the largest rectangle in the histogram inO(N) using a stack, then you may realize that you can actually apply the exact same strategy to find the largest square. The proof is left to the reader for exercise."

And my solution

n = int(input())
arr = list(map(int, input().split()))

def solve(heights):
    maxside = 0
    pstack, hstack = [], []
    currarea, maxside = 0, 0
    heights.append(0)
    for i in range(len(heights)):
        prevwidth = int(1e9)
        while hstack != [] and hstack[-1] > heights[i]: # -_
            prevwidth = pstack[-1]
            width = i - pstack.pop()
            height = hstack.pop()
            if width == height:
                maxside = max(maxside, width)
        if maxside < heights[i] or not hstack or hstack[-1] < heights[i]: # _-
            hstack.append(heights[i])
            pstack.append(min(prevwidth, i))
    return maxside

ans = solve(arr)
print(ans)

Read more »

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

By codinghermit05, history, 4 months ago, In English

Problem Link: https://codeforces.com/contest/1609/problem/A

#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(int n)
{
	if (n == 0)
		return 0;
	while (n != 1)
	{
		if (n % 2 != 0)
			return 0;
		n = n / 2;
	}
	return 1;
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		long long int n;
		cin >> n;
		long long int a[n];
		long long int x;
		long long int sum = 0;
		long long int sum1 = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		for (int i = 0; i < n; i++)
		{
			if (a[i] % 2 == 0)
			{
				if (isPowerOfTwo(a[i]) == 1)
				{	x = (long long int)log2(a[i]);
					a[i] = 1;
					sum = sum + x;
				}
				else
				{
					a[i] = a[i] / 2;
					sum++;
				}
			}
		}
		sort(a, a + n);
		long long int y = (long long int)pow(2, sum);
		a[n &mdash; 1] = a[n &mdash; 1] * y;
		for (int i = 0; i < n; i++)
		{
			sum1 = sum1 + a[i];
		}
		cout << sum1 << endl;
	}
	return 0;
}

Read more »

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

By codinghermit05, history, 4 months ago, In English

Wishing Good Luck to Mr.Tourist. Hope to see him in 4000 by next contest XD. He is the Elon Musk of CP. One day I will be like him. Working towards a better future. All the best to all the readers too!

Read more »

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

By codinghermit05, history, 4 months ago, In English

Serious doubt! Literally every post created by low level coders I find in the community section is full of negative votes (negative support) where as the sole purpose of having a community and discussion forum is to encourage new comers to put up their doubts, and get guidance. Don't we all want to contribute towards a healthy supportive community? At least, let's not demote genuine posts, it maybe a small mischievous act for us, but for the author of the blog, it means a lot. When people post their genuine doubts here, and all we get is dislikes, it created a negative impression about this community and often people decide to quit from here which I believe is bad for us :(

Read more »

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

By codinghermit05, history, 4 months ago, In English

CP gives me both happiness and stress. So I am interested in knowing what people in this community do when they are in anxiety or down in life or when they have tried hard to solve a problem, but never succeeded. Should I make friends to do CP or solving problems alone is enough?

Read more »

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

By codinghermit05, history, 6 months ago, In English

Hello everyone, Just here to do a health check. I hope you and your families are doing well during this lock-down. I was just trying to do some problems and felt that the editorials weren't enough for me since I am a beginner. So I would like to know everyone's opinion on Codeforces starting it's own YouTube channel to upsolve problems after contest. It will provide a greater learning opportunity for beginners like me.

Read more »

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

By codinghermit05, history, 11 months ago, In English

What else could we do as a part of community to support active participation, regardless of gender, age and other backgrounds? Suggestions are welcome :)

Read more »

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

By codinghermit05, history, 11 months ago, In English

Should you be stuck with a problem for long hours and try to come up with a solution or should you spend a hour or so for a problem and then give up and get hints from editorial and try again? I feel guilty for seeing the editorial. (^_^)!

Read more »

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

By codinghermit05, history, 11 months ago, In English

A special Entrance Test should be conducted for Computer Science Aspirants and choices of colleges be given based on it, instead of the current PCM score based system. I am not saying we should force the examination. But it can also be an option for THOSE WHO ARE GOOD IN CODING but bad in Science and other subjects in school. Kids with good coding skills don't get to choose CS (given most priority in college) because of their low GPAs in schools.

Read more »

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