Wednesday, September 6, 2017

[Tutorial] SquareRoot Decomposition + Dynamic Programming in Competitive Programming

Hi guys! ✋
rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain microsoft

You are going to learn how Square Root Decomposition and DP can be mixed to generate harder problems.

This is an awesome math problem on Matrices. It is based on DP + Data Structures(Fenwick Tree/SquareRoot Decomposition). Its a counting problem from CSAcademy Junior Challenge 2017.
Problem Link is here.   

You are given a matrix $M$ with $N,M( \le 2000)$ rows and columns, and you have to count the no of special square submatrices. A square matrix is special if it has all $1s$ on its borders and principal diagonal(top-left to bottom-right). The rest of the matrix can be filled with either $0s$ and $1s$.  
In beginning, the problem seems to be solvable using only DP, but the solution is simply mind-blowing, jaw-dropping and beautiful.  

The trick here is to iterate on diagonals which are $O(N+M)$ in number. Then for each diagonal, count the number of special square submatrices that lie on current diaognal i.e their principal diagonal lies on the current diagonal that we are iterating. 

Lets pick any two points on the diagonal that we are currently at. 
Using DP, we do some preprocessing. Then the question is transformed to given two arrays $L,R$, find the number of pairs $(i, j)$ such that following 3 conditions are met:   
1. $i\le j$ 
2. $L_j \le i$
3. $R_i \ge j$  

We iterate on $j$, and use square root decomposition to solve this problem :)

The video tutorial is divided into 2 parts: 

1. Part1: Approaching the problem and building our solution



2. Part2: The Square Root Decomposition part



Refer the Video Description to find the links to problem link and other relevant information.
If you liked my efforts, please hit the like button 👍, subscribe and share the videos among your college :D  

Have a good day! 😆


Wednesday, August 30, 2017

An Interesting Math + Data Structure Problem from Codeforces (Round #430)

Hi guys! ✋
rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain microsoft

This is a data structure(TRIE) + math based problem from Codeforces Round #430.
Problem Link is here.   
You are given an array $A$ of size $N$, and you have to perform $M$ operations on it.  
In each operation, you are given an integer $x$, and you perform XOR operation of every element of the array with $x$. Note that the array is updated after every operation and subsequent operations are performed on modified array. At end of every operation, you need to print the mex value of the updated array.     

NOTE: mex of a set $A$ is the least whole number ( $\ge 0$ ) which is not present in $A$.    
Check out the following video where I've described the solution:
CodeForces Round 430 - Problem D Tutorial (Number Theory, Trie)

Refer the Video Description to find the links to source code and problem link.
If you liked my efforts, please hit the like button 👍, subscribe and share the videos among your college :D  

Have a good day! 😆


Tuesday, August 29, 2017

An Interesting Number Theory Problem from CSAcademy(Round #43)

Hi guys! ✋
rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain microsoft

This is a greedy, math problem from CSAcademy Round #43.
You are given two integers $N,K$ and you are required to print an array of $N$ distinct integers $<10^6$ such that there are exactly $K$ pairs $(a[i], a[j])$ with their gcd as $1$.  
Check out the following video where I've described the solution:
CSAcademy Round 43 - Coprime Pairs Tutorial (Number Theory)

Refer the Video Description to find the links to source code and problem link.
The family 💓 has grown to 600+ subscribers and I thank you guys for the love and support :)  

If you liked my efforts, please hit the like button 👍, subscribe and share the videos among your college :D  

Have a good day! 😆


Friday, August 25, 2017

YouTube Playlist for Dynamic Programming

Hi guys! ✋
rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain microsoft

I've put in a lot of my efforts this time, kept the video detailed so that a lot of people (beginners for sure) are able to understand:
1. How to approach problems based on Dynamic Programming?
2. How to think of DP states?
3. How to build the DP recurrence relations?
4. Can DP problem be solved faster using MATRIX EXPONENTIATION? ✌

Beginners will surely learn a lot, lot, lot from this. 
Check out the following videos:
1. Intro to DP: How to approach DP states, Recurrences 
2. Dynamic Programming + Matrix Exponentiation

Check the Video Description to find the links to source code and problem link.
Finally, the family 💓 has grown to 500+ subscribers and I thank you guys for the love and support :)  

If you liked my efforts, please hit the like button 👍, subscribe and share the videos among your college :D  

Have a good day! 😆


Saturday, August 19, 2017

Video Tutorial For a SquareRoot Decomposition Problem - HILLJUMPING

rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain microsoft

Hi
I've put in a lot of my efforts this time, kept the video detailed so that a lot of people including beginners are able to understand how to solve this tough squareroot decomposition problem HILLJUMPING from Codechef August 17 Long Challenge.

You can learn about SquareRoot Decomposition, binary search, and how a simple and beautiful solution is built up, starting from scratch :D

Beginners will surely learn a lot, lot, lot from this. 
Check out the video editorial here.
Check the Video Description to find the links to source code and problem link.
If you do not want the problem description, skip to 3:25
Then I explain my approach till 14:50 after which code discussion begins.

Also, YouTube decreased the volume level after upload. So please use headfones, and if any of you
has a solution to this, let me know!


Friday, August 18, 2017

My YouTube Channel for Competitive Programming

rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain microsoft

My very own YouTube Channel

Tags: video-tutorials,YouTube,data-structures, algorithms

Hi everybody,

I've finally launched my very own YouTube Channel here.

Its a kind request to LIKE the video if it helped you. 
This is important for me as more likes builds a trust for future viewers :)

At present, I plan to upload my video screencasts of online contests and video tutorials of some interesting programming problems that I encounter during daily online contests.

The pattern each video follows is:  
1. Problem Description  
2. Explanation/Solution  
3. Code Implementation/Discussion      

As a beginner, I was a bit slow while talking and I request all of you to watch the videos at 1.25x or 1.5x speed for better experience.

To begin off, I've covered some problems from the [Codechef August Long Challenge](https://www.codechef.com/AUG17).

1. [Palindromic Game] (Analysis based, medium)  
=> Video Link 

2. [Chef and Fibonacci Array] (Medium DP)
=> Video Link 

3. [Strings and Graphs] (Interesting analysis, medium-hard)  
=> Video Link

Video for Hill Jumping will be coming soon :)  
EDIT: Here is the video editorial for Hill Jumping.

Why should you subscribe to this channel:
1. You couldn't solve problems I make videos about: majorly covers beginners and intermediate level coders.    
2. You face difficulty in understanding the text editorial.  
3. You enjoy solving difficult yet interesting problems.
4. You really wanted some YouTube channel that talks about problems based on data structures and algorithms, and discuss how they can be solved.  

I hope this will help many people. Please subscribe and like the videos if you found them helpful.
Comment if you face any difficulties or if you have any recommendations for me.

With my common sense and your feedback, I hope the future videos will be of much greater quality :)  

Have a good day!



Saturday, July 22, 2017

Tips for How to Prepare for Placement Interviews

rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain microsoft

Tags: placement, interviews, data-structures, algorithms

Hi! Today I will write about some tips, tricks and hacks I have found from my experience in attempting recruitment tests, interviews.

I will begin by giving a brief introduction about myself.
I have done B. Tech. in Electrical Engineering from IIT Roorkee. I have graduated 2 months back, and now working in Microsoft for over a month.

I started off competitive programming in 2-2(2nd Year 2nd Semester). So I had around 1.5 years of experience in competitive programming while I was sitting for placement tests. Having a strong background in competitive programming really saves your ass while others keep reading geeksforgeeks to prepare themselves.

How to crack the interviews and get a decent job?
So, the organizations will be coming in many colleges soon, and conduct their shortlisting tests.
Now, I will be talking very short and to the point. Each point is important.

Basic Skill Set (BSS): 
1. Quick implementation & debugging (practise questions on codeforces, hackerrank, participate in contests)
2. String Matching (important, KMP, Z-Algorithm, etc)
3. Binary Search, Sorting, STL (sets, maps, unordered set/map, vector, sort) - very very very useful
4. Data Structures - (Linked Lists, stacks, queues, BIT useful, Segment Tree - asked in Google)
5. Dynamic Programming - very very important (medium level problems, all companies ask)
6. Binary Trees & BST - super important! (All companies ask this)
7. DFS/BFS questions on Graphs (Dijsktra and flows are rarely asked)
8. DP on Trees (yes, an important topic)
9. Greedy, Backtracking - (Important, can be tricky)
10. Math Concepts like Prime Seive - Not that much important
11. Bitmask DP - sometimes asked in interviews, cover it later.

I think this is enough for cracking through most of the recruitment tests. Though there are always many other topics that can be covered, but I would suggest don't get overwhelmed and focus on these first. Once you are ready with these basics, you should move on to study other Data Structures and Algorithms. Knowing more and in detail will always make you more interesting and awesome.

Many recruitment problems are based on usages of sets, maps.
Do many practise problems based on them. Eg: see this, and the solution.

People who don't do CP should immediately do the following:
1. Need to improve implementation, debugging skills.
2. Learn the basic set of data structures and algorithms as mentioned above.
3. Begin by doing all 37 problems on GeeksForGeeks under array category.
4. Move on to DP on GeeksForGeeks.
5. For sets, maps I think problems on CodeForces like I mentioned above will be better.
6. Cover other topics like greedy, dfs/bfs from GeeksForGeeks.
7. Linked list, binary trees and their traversals. (Important!)

This should take around 2 weeks. I don't think people who are consistently doing CP would face the need of doing linked list, stacks, etc from geeksforgeeks. But its good if you give it a fast skimming read.

What next?
Now start off at interviewbit and solve problems there so that you familiarize yourself with verdicts like WA, AC, etc and also how to respond in case of TLE or WA. This will improve your implementation and debugging skills. This will clearly help you understand the various concepts like DP, trees, etc.

You must also participate in the ongoing challenges on sites like Codechef, Codeforces, Hackerrank, etc.

Once you are stable blue on CF around 1700, you can easily clear the recruitment tests. Then all you have to do is brush up your explanation skills so that you can clear the interview rounds too.

NOTE: Speed is important. Many times people fail by 10-15 mins to implement the algorithm correctly. This will really turn you off. So keep practicing everyday!

Tips for recruitment tests:
1. Be fast. Don't just keep on waiting for finding the solution.
2. If stuck on problem, proceed to next. First solve all of those that are easy.
3. At the end, ALWAYS submit the worst brute force solution with no matter what complexity. YES! The test cases are many times weak, and you get pretty high score.
4. You must be familiar with Python inbuilt functions involving combinatorics, permutations and string functionalities too. It can prove to be very beneficial ;)
5. This tip is more of a personal experience. In one of the test, I was getting only a score of 25. I soon realized that the  for loop conditions weren't true and I was simply printing 0. When I corrected it, I got a score of 75. Yes! so I had to basically see that if I am getting a WA in some test case, I need to print 0 there. Finally I used binary search on the values of variables(size of array, first element of array) to identify those test cases, and simply print 0. Basically what I did was used an infinite while loop with some condition like $100<n$ and $n<500$ so that I get the verdict TLE, and I am able to figure out those test cases where I was getting WA.


Tips for interviews:
1. Be humble. Don't give the slightest vibes of overconfidence or arrogance.
2. Never give up. If the problem asked seems difficult at first sight, don't lose out confidence. See what is given, what you have to find, and try doing it for small test cases. Then maybe you will find a pattern.
3. Speak as you think. Don't just keep scribbling on paper. Let the interviewer know about how you are approaching the problem.
4. If problem seems difficult, give the brute force solution and its complexity. Then try optimizing it, maybe using dynamic programming or some greedy solution.

Don't think you don't have time :D
Just start doing already!
Feel free to write your queries, I am always there to help :)

Art of Time Management | Achieving Multiple Things in Life

rachit jain blog, Rachit Jain, rachit jain iit roorkee, rachit jain iitr, rachit iitr,rachit codechef, rachit hackerrank, rachit jain micr...