Posts

LC 160 : Two Pointer - New Concept

 160. Intersection of Two Linked Lists public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA == null || headB == null){ return null; } ListNode pA = headA; ListNode pB = headB; while(pA != pB){ pA = pA == null ? headB : pA.next; pB = pB == null ? headA : pB.next; } return pA; } }

Sliding Window: LC 2024 - Maximize the Confusion of an Exam (Optimized solution)

 Description - Given a binary array nums , you should delete one element from it. Return the size of the longest non-empty subarray containing only 1 's in the resulting array . Return 0 if there is no such subarray.   Example 1: Input: nums = [1,1,0,1] Output: 3 Explanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's. Example 2: Input: nums = [0,1,1,1,0,1,1,0,1] Output: 5 Explanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1's is [1,1,1,1,1]. Example 3: Input: nums = [1,1,1] Output: 2 Explanation: You must delete one element. class Solution { public int maxConsecutiveAnswers(String ak, int k) { int i = 0; int[] freq = new int[15]; char[] sc = ak.toCharArray(); for(char c: sc) { ++freq[c-'F']; if(freq[0] > k && freq[14] > k) --freq[sc[i++]-'F']; } return ak.length()...

Sliding window: LC - 904. Fruit Into Baskets - Optimal solution

 It is a great study material for learning the algorithms. It need to understand how they are doing it and space optimization. Problem statement: You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where fruits[i] is the type of fruit the i th tree produces. You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow: You only have two baskets, and each basket can only hold a single type of fruit. There is no limit on the amount of fruit each basket can hold. Starting from any tree of your choice, you must pick exactly one fruit from every tree (including the start tree) while moving to the right. The picked fruits must fit in one of your baskets. Once you reach a tree with fruit that cannot fit in your baskets, you must stop. Given the integer array fruits , return the maximum number of fruits you can pick . Example 1: Input: fruits ...

Leetcode - Presum

 Ref the presum questions 325. Maximum Size Subarray Sum Equals k 560. Subarray Sum Equals K 525. Contiguous Array 1248. Count Number of Nice Subarrays 1371. Find Longest Substring Containing Vowels in Even Counts $ 930. Binary Subarrays With Sum 974. Subarray Sums Divisible by K 523. Continuous Subarray Sum 2845. Count of Interesting Subarrays 528. Random Pick with Weight 1124. Longest Well-Performing Interval

AOSP Question

 What is AOSP? What is Android Boot Process? What is Project Treble? Why is Project treble required? What is the fragmentation of Android or the architecture of Android? What is the role of the Application layer? What is the role of the Framework Layer? What is the role of the HAL Layer? What is the role of the Kernel Layer? What is HIDL? How do we implement it if want to add a new HW? What is AIDL? What is GSI? What is VNDK? how it is different from NDK? How to add a new Device in AOSP? What is the role of the BoardConfig file? What is the role of Manifest.xml? What is a repo tool? How we can use the repo tools? If GIT is already there why do we need to use the repo? How to create a new manifest in the repo? How to use the existing manifest in the repo? What "repo status" command will do? How to add the project to the manifest file in the repo? What are the challenges that you faced in repo sync? What build tools exist in AOSP? What is the SOONG build system? How bp file is ...

Interview Question

Interview question asked: What is MVVM ? Why it is different from MVC? What is dependency injection? What is observer pattern? What is system service and how to implement it? HAL AIDL implement? Stable AIDL in AOSP? What is JNI?