Wednesday, January 6, 2021

Leetcode discuss: 839. Similar String Groups

 Here is the link. 

Lesson learned - C# - Union Find - FindParent API - Union API - Failed

Jan. 6, 2020
Introduction
It is the last algorithm of my Leetcode mock facebook onsite interview. I wrote Union Find algorithm and came cross failed test case.

Failed test case - 60/77
"kccomwcgcs","socgcmcwkc","sgckwcmcoc","coswcmcgkc","cowkccmsgc","cosgmccwkc","sgmkwcccoc","coswmccgkc","kowcccmsgc","kgcomwcccs
The string is marked using index starting from 0.
0 - kccomwcgcs
1 - socgcmcwkc
2 - sgckwcmcoc
3 - coswcmcgkc
4 - cowkccmsgc
5 - cosgmccwkc
6 - sgmkwcccoc
7 - coswmccgkc
The string is denoted as strs, so strs[3] and strs[7] are similar, so Parents[7] = 3; later strs[5] and strs[7] are similar, so Parents[7] = 5; actually the first one is to union 3 and 5, second one is to union 5 and 7. But my code turned out missing first similar pair 3 and 7.

The parents array is wrong, the detail is the following:
parent[0] = 0,
parent[1] = 1
parent[2] = 2
parent[3] = 3
parent[4] = 4
parent[5] = 5
parent[6] = 2
parent[7] = 5
parent[8] = 4
parent[9] = 0

Actually parent[7] = 3, parent[7] = 5, so 3, and 5 and 7 should be one group. One of correct solution is the following:
parent[0] = 0,
parent[1] = 1
parent[2] = 2
parent[3] = 5
parent[4] = 4
parent[5] = 5
parent[6] = 2
parent[7] = 5
parent[8] = 4
parent[9] = 0

What is happening?
The statement in the following should be corrected:

parents[j] = FindParent(i, parents);

It should be:

parents[FindParent(j, parents)] = FindParent(i, parents);

The following code could not pass online judge. I wrote in my Leetcode premium Facebook mock interview.

Union API
The union API should be remembered. There are two FindParent calls in the statement.

public class Solution {
    // union find algorithm
    public int NumSimilarGroups(string[] strs) {
        if(strs == null || strs.Length <= 1)
            return 0; 
        
        var length = strs.Length;         
        var parents = new int[length];
        
        for(int i = 0; i < length; i++)
        {
            parents[i] = i; 
        }
        
        for(int i = 0; i < length - 1; i++)
        {
            var first = strs[i];
            
            for(int j = i + 1; j < length; j++)
            {
                var second = strs[j]; 
                
                if(runSimilarCheck(first, second))
                {                     
                    parents[j] = FindParent(i, parents); // Union i and j API - it should have two FindParent API calls in the statement - added after mock interview onsite
                }
            }
        }
        
        // run again 
        for(int i = 0; i < length; i++)
        {
            parents[i] = FindParent(i, parents);
        }
        
        var count = 0; 
        for(int i = 0 ; i < length; i++)
        {
            if(i == parents[i])
            {
                count++; 
            }
        }
        
        return count; 
    }
    
    private bool runSimilarCheck(string s1, string s2)
    {
        var length = s1.Length; 
        
        var first = -1; 
        var second = -1; 
        var count = 0; 
        
        for(int i = 0; i < length; i++)
        {
            if(s1[i] != s2[i])
            {
                count++; 
                if(first == -1)
                {
                    first = i; 
                }
                else if(second == -1)
                {
                    second = i; 
                }
            }
        }
        
        return count == 0 || (count == 2 && s1[first] == s2[second] && s1[second] == s2[first]); 
    }
    
    private int FindParent(int start, int[] parents)
    {
        if(start != parents[start])
        {
            parents[start] = FindParent(parents[start], parents);
        }
        
        return parents[start];
    }
}

Sven Carlin: My Strategy For 2021 Stock Market Crash + Probabilistic Outlook!

 Here is the link. 

There is a 14% chance of a 42% stock market crash happening in 2021. On average a market crash, thus a drop larger than 20% happens every 6.92 years. This is a given as we have had 13 stock market crashes since 1928. As it is a given, the key is to have a strategy because you can't predict a crash, you can only take advantage of one if you understand what you are buying and adjust for the probabilities in the market. 0:00 Stock Market Crash 1:00 Key Crash Factor 1:50 Chances for Crash 7:19 Crash Strategy 8:47 My Strategy


Sven Carlin: Intel Stock - I'm Buying For Earnings, Dividends & Buybacks

 Here is the link.


An Intel Stock Analysis has been what most of you requested so, because the stock is down but has good fundamentals and offers a very positive outlook, I went into a deep analysis. I also bought Intel stock for my portfolios because the risk and reward is on the positive investing side despite the murky short term outlook that many analysts have. When it comes to buying Intel stock, one has to differentiate between the negative news or noise that has pushed Intel's stock price below $50 and the fundamentals that still look good with high cash flows, strong buybacks and a growing dividend. Intel will definitely lose market share as the environment it operates is more and more competitive, but what is a key investment factor, the semiconductor sector is a growth one, and Intel can keep growing no matter the competition. AMD, NVDA, QCOM and others will do their thing for sure and eat into INtel's moat, but it is most likely Intel will keep growing. In a conservative growth scenario of just 3% per year, and investment into Intel now would likely lead to great long term returns and that is why Intel is a stock to buy now. There are also risks, Intel could end up like IBM, but it is more likely it will end up like Apple stock. Intel now reminds me of Apple in 2016 because the fundamentals were there but the analysts were all worries about the lack of innovation with the new iPhone and consequently lower revenue growth and no profit growth. They were completely right, but the stock went from $100 to the current $500. Enjoy the video: 00:00 Intel stock analysis 01:52 Intel stock price 05:13 Why Intel stock down? 06:29 Analysts downgrades 09:34 Market noise 11:34 Business environment 14:37 Business outlook 16:14 Intel growth potential 17:14 Intel Q2 Earnings 17:57 Comparison to AMD, NVDA 19:00 Intel guidance 20:09 Fundamentals 21:59 Intel buybacks 22:39 Apple comparison 23:49 $10 billion buyback effect 24:37 Intel CEO 24:58 Intel dividend 25:36 Intel stock valuation 27:26 Risk and reward


KSS stock: Jan. 6, 2020 - Do not sell at lowest point in last 365 days! Study department store sector

 Jan. 6, 2020

Introduction

It is so interesting to write a story of myself as a KSS share holder. I sold at lowest price at $20 dollars, in less than two months, KSS went up 100%. What lessons should I learn? 

KSS stock


First I should think about the chance I can hold the stock. I only had $20,000 dollars in my IRA account, and it is better for me to hold the share, and learn more about business. Think about lowest price in last 365 days instead. 

I did not know that there are less than 10 department store stocks in NYSE. I did not know KSS stock is strongest one to rebound in next two months, almost 100%. 



Tuesday, January 5, 2021

Google India | New Grad 2021 | Bangalore/Hyderabad | October 2020 [Reject]

 Here is the link. 


Take my notes in the following:

Facts or arguments:

If you have not explained your approach, reached at right optimality and written code for 2 problems in a round, consider that interview as a doomed. No one will tell you this, but yes you are expected to do 2 questions flawlessly to get a HIRE verdict. Follow-ups may not be expected to be super correct but 2 questions must be coded and explained without their follow up variants. This comes from my extensive research and own experience.


My Background

  • Final year student, B.Tech. CSE from a well known tier-2 college in India.
  • Good amount of dev experience in Full Stack, Mobile and Embedded Linux.
  • Internship in an AR hardware startup.
  • Have an offer from a Unicorn Startup (Campus Placements).
  • Decent academic record and did competitive coding for about an year (Not including LeetCode).

How I got the interview?

Recruiter approached me through email in the month of June (before my campus placements started) asked for fresh copy of my CV. Later in August I was contacted for a Google meet briefing and was told that I have been shortlisted for first round of Telephonic Interview, what's the process is going to be further and so on.

I don't know exact details of why I was approached by recruiter in the first place, but that could be due to Resume/LinkedIn profile/Kickstart performances. Try to maintain all three IMHO.

Preparation Style and Skill Level

At present and just before onsites, I had completed 607 questions with a split of 131 easy, 372 medium and 104 hard questions, Apart from this as I mentioned, I have some competitive coding experience of about 20-25 contests on Codeforces/Codechef.

My LeetCode contest rating is about 1800, with 25 contests so far.

Before telephonic rounds I had completed around a 500 questions. I don't remember the exact ratio of E:M:H but it was quite similar to what it is now.

My grinding intensified in first 3-4 months of lockdown, but I was more or less regular after that too.

The Telephonic Round

It was scheduled sometime around August end or September start.
I was asked 2 questions with follow up on 2nd question after some modifications.
First question was just a warmup, really easy implementation based. Second was a modified form of multisource parallel BFS. Kinda similar to Rotten Oranges, but with an element of parallelism involved where you had to run multisource BFS for two different sides (or lets say, two teams).

For this BFS question a matrix was provided initially, after I completed my solution he gave me a follow up that do we really need to pass a matrix to our function to solve this? He basically wanted an approach where you can only access matrix from an API and can't edit any cells.

Tip 1: This happens a lot in Google interviews, they want production level code from you in very first go actually. By production level I mean, use of APIs, proper abstractions and Iterator patterns (if problem involves iterating over some data). Using static variables or any other stuff like that will give nothing but wrong impression and will result in a NO-HIRE verdict irrespective of the fact that you were able to solve problem or not.

Tip 2: Follow ups in Google interviews are much more common than any other firms (or for those which I have interviewed with). You should keep that in mind that solving the initial question alone will almost never be enough and a follow up is waiting for you surely.

This round went well, I was able to solve everything nicely.
Recruiter called few days later and gave me my feedback. Although it was a green signal for on-sites, review wasn't really what I was expecting.

Review for Telephonic Interview

They said although my thinking and algorithmic skills were fine, I had done few syntax errors on the way. And even though I was able to rectify my code at the time of dry run or debug phase, It's not expected to be like that and should be perfect on the first go.

Yes you heard me right, They knit pick everything and why won't they. When you have a huge pool of talented applicants, things like these happen. So make sure you keep your mind and eyes open at all the times as this almost costed me onsites.

Onsites

Initially onsites were supposed to happen the very next week but my new point of contact advised me to take as much time as I needed for preparation as there will be a 9 month cool-down if I get rejected now. I then asked for 2 weeks time and he was okay with it.

For those who don't know, for onsites Google has 5 total rounds. 4 tech interviews, 1 Googlyness round.

Timeline: 3 tech rounds on one day, and remaining 1 tech + Googlyness round on some other day only if review is positive from first three rounds.

Onsite Interview 1

  • Question 1

    Given an array A, where A[i] = j denotes the fact that player j finished the race before player i, and for the winner of race let's  say player k, A[k]=-1.  
    You need to print the order of the positions of players after race finishes
    
    Follow up: What if the data (array A) got courrupted, how will you take care of that. Return  -1 if there data is courrupted and order of player otherwise.
    

    Pretty easy warmup question. First version of the problem is pretty easy, just create an inverse mapping of array values and index and everything else is basically clear.

    For the second part I suggested that we can visualize this mapping as a dependency graph and then apply topological sort on it. If there is an error like cycle etc, it will be detected.

    He looked satisfied with this approach however I could clearly see that he knows that there exists a simple solution for this. My hunch is that this includes some kind a case work to enumerate all the possible error cases. Topological sort just felt natural to me at the moment.

  • Question 2
    This was a hard one for me. As a matter of fact this problem appeared in a contest very next day of my interview.
    Window Queries Problem.
    Idea here is a tricky modification of merge intervals and sliding window.

    This is in fact a classic example of how Google interview questions are like, they are hardly ever about a hard CS concept, an algo or a fancy DS. But they are all about observation and application.

    I came close to solving this problem, finally gave right idea but at that point only 5 minutes were remaining so he asked me to code just the brute force solution.

Before I forget, I would like to add that no matter what anyone says, If you have not explained your approach, reached at right optimality and written code for 2 problems in a round, consider that interview as a doomed. No one will tell you this, but yes you are expected to do 2 questions flawlessly to get a HIRE verdict. Follow-ups may not be expected to be super correct but 2 questions must be coded and explained without their follow up variants. This comes from my extensive research and own experience.

Onsite Interview 2

This was 30 minutes after the first one.

Okay this was one of my worst interview performances ever, primarily because of bad taste from first interview as a result of not being able to code 2nd problem.

Given an array A, and the Q queries with each query having an integer K,
Return an interval A[i:j] that minimizes the following expression for each query/given K
| sum(A[i:j])-K |

Quickly gave a sub optimal, improved brute force solution involving prefix sums to calculate all the possible sum values of intervals, use a hashmap of these sum->intervals and binary search over keys of the hashmap to find value nearest to K

She needed a better approach. I should have given up, but I did a pretty bad thing, went on to try a wrong idea without thoroughly exploring it and checking it for correctness, so in middle of it I realize that its wrong and finally went with sub optimal solution. This interview was bombed for sure.

Here people have discussed a nice approach to this problem.

Onsite Interview 3

This was an enjoyable interview, but then again I was able to do only one question, actually the interviewer kept modifying it so you can say it was one questions with a lot of follow ups.

The question was exactly the same - Maximum Points You Can Obtain from Cards

Without wasting anytime I threw a DP solution with code, O(NK). He asked if I could do any better. I was confused at first, and reason for that is my skillset/background. I have solved problems on OJs, and not given many interviews. For me a problem like this screems dynamic programming if you have not given me any constarints to start with. And that is how situation was at that point. Immediate idea was to try my greedy hypothesis, and that failed as expected. Over next 5 minutes I came up with some micro optimization on DP solution but he finally said that linear time is possible and I should think in that direction. He said my core idea was right, but one insight is missing. This hint was enough and I came up with expeted approach. He asked me to code it, went over it and did some more micro optimizations.

Then he asked some follow ups.

Overall this was a good interview but I knew that even this one is practically screwed as I took alot of time in supposedly warmup variant of this question.

Tip 3: Interviewers will be happy to provide you with hints when you are stuck but keep in mind that every hint is a -10 points on your score cards in reality.

Onsites Review

Immediately after this final interview I had chat with my recruiter. She shared review and as expected overall it was not positive. Feedback stated that my coding style was nice, it was clean and upto the standard but my algorithmic skills were not up to the mark.

Well ofcourse I was sad, questioned my abilities and luck as any normal human being would do. But I accepted verdict nicely. For the next several days I went on to see what I missed in my preparation and what went wrong.

So here is what I lacked.

What went wrong/missing?

If you open up LinkedIn and see most of new grad or L3 engineers at Google India, you will find one thing common. All of them have extensive Competitve Coding profiles. Many of them are Candidate Masters or even Masters at codeforces.

In a country which produces millions of software engineers a year, competition is bound to be tough. We in India are at a point where competitve coding is compulsory to get a job and not a mind sport anymore.

So yes, a hardcore competitve coding experience was missing from my profile but that is not the only reason I failed, it was something else, it had something to do with my style of preparation.

  • Most of my preparation was focussed on getting a campus placement and not an offcampus job. Oncampus placements have only one hurdle, online assessment. Once you clear OA, rest of the interviews are damn easy. But here in campus drives, OAs are focused on DS/Concept heavy questions for example having knowledge of articulation points, Bell's numbers and DP with bitmasking.
  • This is quite opposite to Google interviews which are all ad-hoc, and logic focused
  • I am now quite good with all these fancy DPs and complicated algorithms. But I suck at greedy problems.
  • Even knowing that I lack ability to crack greedy/constructive problems, I ignored it (There is less chance that a non classic greedy problem would appear in any OA, and classic greedy problems I have got covered)
  • Leetcode contests are helpful, but these days they are not, atleast for India. The easy first problems are sometimes about string formatting or running a loop, this will never appear in any companie's recruitments in India. The other problems at last are almost 3x difficulty of first two sometimes and hence whole contest becomes imbalanced.

So how will I prepare now?

Having seen that recruitment at Google requires alot that I dont have, a smart thing would be to work on that.
For the time being I will shift to websites like Binary Search and AtCoder where problem statements are short and don't require pointless mathematics that codeforces/codechef requires and at the same time helps in building good reasoning and logic.
I would still give weekly contests here, and hope they improve and become balanced.

Word of suggestion to LeetCode

There is a great need of content that is India focused, level of interviews here is just a little harder than west world. Maybe leetcode-in or something like that would be helpful as I am sure there is a huge Indian traffic on this site.

PS: Thanks LeetCode for the job offer I have right now, It might not be sufficient but for sure is a neccessary resource for coding interviews :).

Word of advice to New-Grads aspiring for Google

  • Stop wasting time in anything else you are doing right now, start today because when this interview chance knocks on your door, you might not be ready and wished you had started training a year earlier.

  • Extensive competive coding experience + lesser dev experience is often better that lesser competitve coding experience and more dev experience atleast for freshers.

Feel free to comment if you agree/disagree with my thoughts. Also if you have any better approaches for any of the above problems, please share. Thankyou

binary-searchgoogle-indiacompetitve-programming

HSE.TO stock: Do not sell at lowest price - last 365 days lowest price

 Jan. 5, 2020

Introduction

It is hard for me to learn the lesson. Do not sell at lowest price last 365 days lowest price. I made mistake on HSE.TO last Sept. 

Lowest price 365 days



Adam Khoo: Professional Stock Trading Course Lesson 1 of 10 by Adam Khoo

 Here is the link. 

If you want to learn how to trade stocks profitably, even if you are a complete beginner, The Professional Stock Trading Course by Adam Khoo is designed to give you all the tools and strategies to trade stocks confidently and profitably. The Professional Stock Trading Course is available for enrolment at http://bit.ly/2H5ZoHF Stock investment & trading insights by Adam Khoo shows you profitable trading and investment opportunities in today's stock markets. These are essential strategies for stock traders and investors who want to improve their investment and trading performance. Adam Khoo is a professional stocks and forex trading and the best-selling author of 'Winning the Game of Stocks" and "Profit from the Panic". Thousands of students have profited from his sharp investment insights into the world of stock investing and trading.

Expr stock: Missing bottom 0.86/ share

 Jan. 5, 2020

Introduction

USA is in trouble. Expr stock went down 0.86/ share, and then stimulus plan brought up the share to 0.96/ share. I like to document my positions. 

Expr stock




Monday, January 4, 2021

Aswath Damodaran: Youtube channel - Finance professor

Here is the link. 


Finance illustrated: The Truth About Trading Gurus - My Research

 Here is the link. 

Traders who make money don't make trading courses; they are busy beating the market and building their wealth. Stay away from anyone who claims their "Trading Secrets" will make you a profit. There are no shortcuts, and it's not happening without putting in your own honest hard work and dedication.😎 In this video, you will find out the truth about Youtube Trading Gurus, Trading courses, and Scams. You will learn the schemes, the tactics, the hidden dirty secrets that these self-proclaimed "Trading Experts". don't want you to know.🕵️‍♂️ In fact, I researched 10 of the most popular Trading Gurus that I see when browsing the world of Finance Youtube. Why are they making videos? Why you should or shouldn't spend your money on their trading courses? What is their true motivation for making Youtube videos and teaching you their trading "secrets". I have always believed that great traders really don't have the time to be making videos and courses, especially when making money in the market is a lot easier than on Youtube. 00:00 - Introduction 02:06 - Rayner Teo 05:38 - Andrei Jikh 08:04 - Ricky Gutierrez 12:18 - Graham Stephan 14.13 - Aswath Damodaran 16:13 - Adam Khoo 18.23 - Raging Bull 21:50 - Financial Education 24:25 - Warrior Trading 26:38 - Sven Carlin You might be thinking: "Hey, You're making Youtube videos as well." 🤔 True, but I've never proclaimed that I am a great trader or that I have some never before seen trading secrets to share with you. I've also never sold any ridiculous trading courses to beginners. In fact, I've always maintained that almost everything should and can be learned for free, on google, or in books on investing, trading, etc.📚


Nvidia and AMD could fall victim to their own success, but that would create a buying opportunity, trader says

 Here is the link. 

Two of this year’s best-performing semiconductor stocks have hit a wall.

Chipmakers Nvidia and AMD have diverged from their competitors this month, falling nearly 2% and 0.5%, respectively, while the VanEck Vectors Semiconductor ETF (SMH) has climbed nearly 4.5%.

The lag could make for a near-term buying opportunity, JC O’Hara, chief market technician at MKM Partners, told CNBC’s “Trading Nation” on Wednesday.

“This is a market where you want to own leadership. That’s the only way for you to outperform a benchmark,” he said. “When we look at the 19 semiconductor names within the S&P, we find leadership in Nvidia and AMD.”

As of Wednesday’s close, Nvidia was sitting on a year-to-date gain of nearly 123.5% and AMD was up over 101%.

S&P 500 semiconducts year-to-date performance

  1. NVDA 120
  2. AMD 98
  3. TER  73
  4. QCOM 73
  5. LRCX 64
  6. SMH 54
  7. IPGP 53
  8. KLAC 45
  9. XLNX 45
  10. MXIM 43
  11. AVGO 42

Semiconduct ETF: iShares PHLX Semiconductor ETF (SOXX)

 Here is the link. 

Top 10 Holdings (59.14% of Total Assets)

Get Quotes for Top Holdings
NameSymbol% Assets
Qualcomm IncQCOM8.34%
Broadcom IncAVGO7.80%
Texas Instruments IncTXN7.65%
NVIDIA CorpNVDA6.76%
Intel CorpINTC6.40%
Micron Technology IncMU4.75%
Lam Research CorpLRCX4.54%
Applied Materials IncAMAT4.52%
NXP Semiconductors NVNXPI4.25%
Taiwan Semiconductor Manufacturing Co Ltd ADRTSM.TW4.13%

Sunday, January 3, 2021

SWI stock: Valuation

 January 3, 2020

price/earnings 

SWI 124.75  peers 70.65

Price/ project earnings

SWI 14.19 - peers 89.76

Price/ Book

SWI 1.67 - peers 39.76

Price/Sales

SWI 4.65 - peers 15.78

Price/ CashFlow 

SWI 12.66 Peers 153.19

Price to Earnings/Growth

SWI 0.08 - Peers 3.01

Earnings Growth

SWI 400.00 - Peers 126.43

Sales growth 

SWI 10.50 - Peers 30.47

SWI stock

  1. Price/ Earnings 124.75
  2. Price/Projected earnings 14.19
  3. Price/Book 1.67
  4. Price/Sales 4.65
  5. Price/CashFlow 12.66
  6. Price to Earnings/Growth 0.08
  7. Earnings growth 400.00
  8. Sales Growth 10.50

Joseph Carlson: The 5 Most Overvalued Stocks In the Market | Joseph Carlson Ep. 131

Here is the link. 

The 5 Most Overvalued Stocks In the Market | Joseph Carlson Ep. 131


13 billion buy back - JPM - chase back - 9% of total capital - 5% instant gain 

  1. TESLA stock - same amount as Alibaba, Facebook - baked in the stock - global leader - stock will get hurt; another competitor comes in - $630 billion dollar - profitable - lose market share; 640% return in one year; Apple has 50 billion dollar income. 
  2. Shopify - 1200, fair value 400, 142 billion capital, 2 billion dollars revenue - price into it
  3. NFLX  164% premium, fair value $200, last value $350 - disney, HBO max, NBX - NFLX revenue growth 30%/ year, market margin 
  4. SQ - 199% premium, fair value $70/ share, trade value $240/ share -