Lava Interview Question for Front-end Software Engineers


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int GetNumberOfWays(int[] a, int k)
        {
            int ways = 0, wr = 0, wl = 0, zc = 0, best = 0;
            while (wr < a.Length)
            {
                if (zc <= k)
                {
                    if (a[wr] == 0)
                        zc++;
                    wr++;
                }
                if (zc > k)
                {
                    if (a[wl] == 0)
                        zc--;
                    wl++;
                }
                if (wr - wl == best && zc==k)
                    ways++;
                else if (wr - wl > best && zc==k)
                {
                    best = wr - wl;
                    ways = 1;
                }
                
            }
            return ways;

}

- Bharat March 01, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int NumberOfMaxOccurences(int[] input, int k) {
		
		int flippedZeroCount = 0;
		int maxLengthFound = 0;
		int maxCount = 0;
		int leftPos = 0;
		int rightPos = 0;
		
		if(input.length == 0){
			return 0;
		}
		if(input.length == 1){
			if(flippedZeroCount == 0){
				return input[0]==1?1:0;
			}
			if(flippedZeroCount == 1){
				return input[0]==1?0:1;
			}
		}
		
		while(rightPos<input.length){
			
			if(input[rightPos] == 0 ){
				flippedZeroCount++;
			}
			
			
			if(flippedZeroCount == k){
				while(rightPos<input.length-1 && input[rightPos+1] == 1){
					rightPos++;
				}
				if(rightPos-leftPos+1 > maxLengthFound){
					maxLengthFound = rightPos-leftPos + 1;
					maxCount = 1;
				}else if(rightPos-leftPos + 1 == maxLengthFound){
					maxCount++;
				}
			}
			
			if(input[leftPos++] == 0 ){
				flippedZeroCount--;
			}
			
			rightPos++;
		}
		return maxCount;
		
	}

- dadakhalandhar March 12, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More