-
Builder Design Pattern
When you want to create a complex object,1 way is to pass too many arguments in the constructor,have multiple constructors.this makes the code error prone. Other Method, is you create object step by step, so builder pattern can be used. // Builder will have the API to set underlying object’s capabilities.// Make builder as friend…
-
Longest Repeating Character Replacement
https://leetcode.com/problems/longest-repeating-character-replacement/description Example 1: Input: s = “ABAB”, k = 2 Output: 4 Explanation: Replace the two ‘A’s with two ‘B’s or vice versa. Example 2: Input: s = “AABABBA”, k = 1Output: 4Explanation: Replace the one ‘A’ in the middle with ‘B’ and form “AABBBBA”.The substring “BBBB” has the longest repeating letters, which is 4.There…
-
Fruits into basket
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 ith tree produces. You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow: Given the integer array fruits, return the maximum number…
-
Max Consecutive 1’s
Given a binary array nums and an integer k, return the maximum number of consecutive 1‘s in the array if you can flip at most k 0‘s. Example 1: Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2 Output: 6 Explanation: [1,1,1,0,0,1,1,1,1,1,1] Bolded numbers were flipped from 0 to 1. The longest subarray is underlined. Example 2: Input: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3…
-
Longest Substring Without Repeating Characters
Given a string S, find the length of the longest substring without repeating characters. Input:S = “geeksforgeeks”Output:7Explanation:Longest substring is”eksforg”.https://www.geeksforgeeks.org/problems/length-of-the-longest-substring3036https://leetcode.com/problems/longest-substring-without-repeating-characters
-
Longest subarray with sum k
Problem statement: You are given an array and a number K, you need to find longest subarray whose sum is K. For example : Array : {2,1,3, 1,1,1}, K = 3 In this we have {2,1} {3} {1,1,1} 3 sub-arrays whose sum is 3, where {1,1,1} is the longest with length of 3, which becomes…
Subscribe
Enter your email below to receive updates.