A2SV Community Education __ Sliding Window Lecture.pdf
2.1 MB
β
A2SV Community Education Resources.π
π’ Very good resources for A2SV interview prep.
ππ @AceCoding Presents! ππ
π’ Very good resources for A2SV interview prep.
ππ @AceCoding Presents! ππ
Stacks, Queues and Monotonicity.pdf
1.5 MB
β
A2SV Community Education Resources.π
π’ Very good resources for A2SV interview prep.
ππ @AceCoding Presents! ππ
π’ Very good resources for A2SV interview prep.
ππ @AceCoding Presents! ππ
π1
Here are the resources for the topics covered so far. We've also linked them in the Resources tab of the Community Sheet
β’ Python Learning Path
β’ Time and Space Complexity Learning Path
β’ Sorting Learning Path
β’ Stack and Queue Learning Path
β’ Recursion Learning Path
β’ LinkedList Learning Path
β’ Sliding Window and Two Pointers Learning Path
β’ Prefix Sum Learning Path
β’ Heaps Learning Path
ππ @AceCoding Presents! ππ
β’ Python Learning Path
β’ Time and Space Complexity Learning Path
β’ Sorting Learning Path
β’ Stack and Queue Learning Path
β’ Recursion Learning Path
β’ LinkedList Learning Path
β’ Sliding Window and Two Pointers Learning Path
β’ Prefix Sum Learning Path
β’ Heaps Learning Path
ππ @AceCoding Presents! ππ
Google Docs
A2SV Community - Python Learning Path
Make a copy of this doc and go on at your own pace Python Learning Path Introduction
W3Schools GeeksforGeeks YouTube Python Doc Work on these questions from the sheet Basic Data Types
W3Schools GeeksforGeeks YouTube Python Doc Work on these questionsβ¦
W3Schools GeeksforGeeks YouTube Python Doc Work on these questions from the sheet Basic Data Types
W3Schools GeeksforGeeks YouTube Python Doc Work on these questionsβ¦
π’ Important Update for A2SV G6 In person Education Cohort!
If you've received an email from A2SV, congratulations! π Youβve been shortlisted for an interview for the A2SV G6 Cohort!
π Interviews Begin: on Tuesday
π Focus Areas: Make sure to prepare thoroughly on the topics mentioned in the email.
If you havenβt checked your email yet, go check it now and start your preparation! π¨
π @AceCoding Presents! π
If you've received an email from A2SV, congratulations! π Youβve been shortlisted for an interview for the A2SV G6 Cohort!
π Interviews Begin: on Tuesday
π Focus Areas: Make sure to prepare thoroughly on the topics mentioned in the email.
If you havenβt checked your email yet, go check it now and start your preparation! π¨
π @AceCoding Presents! π
π§ Python Quiz: Predict the Output
What will the output be? You can choose your answer below.
@AceCoding Presents!
arr = [[0]] * 5
print(arr)
arr[0][0] = 1
print(arr)
What will the output be? You can choose your answer below.
@AceCoding Presents!
For the above question.
Anonymous Quiz
53%
1οΈβ£ Option A: [[0], [0], [0], [0], [0]] and [[1], [0], [0], [0], [0]]
25%
2οΈβ£ Option B: [[0], [0], [0], [0], [0]] and [[1], [1], [1], [1], [1]]
9%
3οΈβ£ Option C: [[0]] [[1]]
13%
4οΈβ£ Option D: [[0], [0], [0], [0], [0]] Error: List index out of range
π5
β
Sliding window, Two pointers, and Hash Table problem
π‘ 567. Permutation in String
https://leetcode.com/problems/permutation-in-string/submissions/1482104785/
π @AceCoding Presents! π
π‘ 567. Permutation in String
https://leetcode.com/problems/permutation-in-string/submissions/1482104785/
π @AceCoding Presents! π
β
Dynamic Sliding window and hashmap / hashset problem.
This problem has a pattern that repeats a lot : worth revising
π‘ 3. Longest Substring Without Repeating Characters
https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
π @AceCoding Presents! π
This problem has a pattern that repeats a lot : worth revising
π‘ 3. Longest Substring Without Repeating Characters
https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
π @AceCoding Presents! π
π1
Substrings that begin and end with the same letter
You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character.
A substring is a contiguous non-empty sequence of characters within a string.
Example 1:
Input: s = "abcba"
Output: 7
Explanation:
The substrings of length 1 that start and end with the same letter are: "a", "b", "c", "b", and "a".
The substring of length 3 that starts and ends with the same letter is: "bcb".
The substring of length 5 that starts and ends with the same letter is: "abcba" .
Example 2:
Input: s = "abacad"
Output: 9 112131
Explanation:
The substrings of length 1 that start and end with the same letter are: "a", "b", "a", "c", "a", and "d" = 6.
The substrings of length 3 that start and end with the same letter are: "aba" and "aca" = 2.
The substring of length 5 that starts and ends with the same letter is: "abaca" = 1.
Example 3:
Input: s = "a"
Output: 1
Explanation:
The substring of length 1 that starts and ends with the same letter is: "a".
Constraints:
1 <= s.length <= 105
s consists only of lowercase English letters.
You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character.
A substring is a contiguous non-empty sequence of characters within a string.
Example 1:
Input: s = "abcba"
Output: 7
Explanation:
The substrings of length 1 that start and end with the same letter are: "a", "b", "c", "b", and "a".
The substring of length 3 that starts and ends with the same letter is: "bcb".
The substring of length 5 that starts and ends with the same letter is: "abcba" .
Example 2:
Input: s = "abacad"
Output: 9 112131
Explanation:
The substrings of length 1 that start and end with the same letter are: "a", "b", "a", "c", "a", and "d" = 6.
The substrings of length 3 that start and end with the same letter are: "aba" and "aca" = 2.
The substring of length 5 that starts and ends with the same letter is: "abaca" = 1.
Example 3:
Input: s = "a"
Output: 1
Explanation:
The substring of length 1 that starts and ends with the same letter is: "a".
Constraints:
1 <= s.length <= 105
s consists only of lowercase English letters.
< Ace Coding /> π
Substrings that begin and end with the same letter You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character. A substring is a contiguous non-empty sequenceβ¦
question from today interview question
Question: Maximum Sum Score of an Array
You are given a 0-indexed integer array
β’ The sum of the first
β’ The sum of the last
Your task is to return the maximum sum score of
βExamples:
1. Input:
Output:
Explanation:
β’ At index 0: max(4, 4 + 3 - 2 + 5) = max(4, 10) = 10.
β’ At index 1: max(4 + 3, 3 - 2 + 5) = max(7, 6) = 7.
β’ At index 2: max(4 + 3 - 2, -2 + 5) = max(5, 3) = 5.
β’ At index 3: max(4 + 3 - 2 + 5, 5) = max(10, 5) = 10.
β’ The maximum sum score of
2. Input:
Output:
Explanation:
β’ At index 0: max(-3, -3 - 5) = max(-3, -8) = -3.
β’ At index 1: max(-3 - 5, -5) = max(-8, -5) = -5.
β’ The maximum sum score of
βChallenge:
Write a function
You are given a 0-indexed integer array
nums of length n. The sum score of nums at an index i (where 0 <= i < n) is defined as the maximum of:β’ The sum of the first
i + 1 elements of nums.β’ The sum of the last
n - i elements of nums.Your task is to return the maximum sum score of
nums at any index.βExamples:
1. Input:
nums = [4, 3, -2, 5] Output:
10 Explanation:
β’ At index 0: max(4, 4 + 3 - 2 + 5) = max(4, 10) = 10.
β’ At index 1: max(4 + 3, 3 - 2 + 5) = max(7, 6) = 7.
β’ At index 2: max(4 + 3 - 2, -2 + 5) = max(5, 3) = 5.
β’ At index 3: max(4 + 3 - 2 + 5, 5) = max(10, 5) = 10.
β’ The maximum sum score of
nums is 10.2. Input:
nums = [-3, -5] Output:
-3 Explanation:
β’ At index 0: max(-3, -3 - 5) = max(-3, -8) = -3.
β’ At index 1: max(-3 - 5, -5) = max(-8, -5) = -5.
β’ The maximum sum score of
nums is -3.βChallenge:
Write a function
maximumSumScore(nums) that takes an integer array as input and returns the maximum sum score.
< Ace Coding /> π
Question: Maximum Sum Score of an Array You are given a 0-indexed integer array nums of length n. The sum score of nums at an index i (where 0 <= i < n) is defined as the maximum of: β’ The sum of the first i + 1 elements of nums. β’ The sum of the last nβ¦
Leetcode
2219 - Maximum Sum Score of Array
Welcome to Subscribe On Youtube Formatted question description: https://leetcode.ca/all/2219.html 2219. Maximum Sum Score of Array Description You are given a 0-indexed integer array nums of length n. The sum score of nums at an index i where 0 <= i < n isβ¦
< Ace Coding /> π
Substrings that begin and end with the same letter You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character. A substring is a contiguous non-empty sequenceβ¦
β
Free leetcode questions which is 99% similar with the first question :
https://leetcode.com/problems/count-substrings-starting-and-ending-with-given-character/description/
class Solution:
def countSubstrings(self, s: str, c: str) -> int:
count = s.count(c)
return count * (count + 1) // 2
https://leetcode.com/problems/count-substrings-starting-and-ending-with-given-character/description/
LeetCode
Count Substrings Starting and Ending with Given Character - LeetCode
Can you solve this real interview question? Count Substrings Starting and Ending with Given Character - You are given a string s and a character c. Return the total number of substrings of s that start and end with c.
Example 1:
Input: s = "abada", cβ¦
Example 1:
Input: s = "abada", cβ¦
/*
You are given a string s consisting only of lowercase English letters.
We call a substring special if it contains no character which has occurred at least twice (in other words, it does not contain a repeating character).
Your task is to count the number of special substrings.
For example, in the string "pop", the substring "po" is a special substring, however, "pop" is not special (since 'p' has occurred twice).
Return the number of special substrings.
A substring is a contiguous sequence of characters within a string. For example, "abc" is a substring of "abcd", but "acd" is not.
Example 1:
Input: s = "abcd"
Output: 10
Explanation: Since each character occurs once, every substring is a special substring.
We have 4 substrings of length one, 3 of length two, 2 of length three, and 1 substring of length four. So overall there are 4 + 3 + 2 + 1 = 10 special substrings.
Example 2:
Input: s = "ooo"
Output: 3
Explanation: Any substring with a length of at least two contains a repeating character. So we have to count the number of substrings of length one, which is 3.
Example 3:
Input: s = "abab"
Output: 7
Explanation: Special substrings are as follows (sorted by their start positions):
Special substrings of length 1: "a", "b", "a", "b"
Special substrings of length 2: "ab", "ba", "ab"
And it can be shown that there are no special substrings with a length of at least three. So the answer would be 4 + 3 = 7.
l r
a b c d a
Constraints:
1 <= s.length <= 10^5
s consists of lowercase English letters
You are given a string s consisting only of lowercase English letters.
We call a substring special if it contains no character which has occurred at least twice (in other words, it does not contain a repeating character).
Your task is to count the number of special substrings.
For example, in the string "pop", the substring "po" is a special substring, however, "pop" is not special (since 'p' has occurred twice).
Return the number of special substrings.
A substring is a contiguous sequence of characters within a string. For example, "abc" is a substring of "abcd", but "acd" is not.
Example 1:
Input: s = "abcd"
Output: 10
Explanation: Since each character occurs once, every substring is a special substring.
We have 4 substrings of length one, 3 of length two, 2 of length three, and 1 substring of length four. So overall there are 4 + 3 + 2 + 1 = 10 special substrings.
Example 2:
Input: s = "ooo"
Output: 3
Explanation: Any substring with a length of at least two contains a repeating character. So we have to count the number of substrings of length one, which is 3.
Example 3:
Input: s = "abab"
Output: 7
Explanation: Special substrings are as follows (sorted by their start positions):
Special substrings of length 1: "a", "b", "a", "b"
Special substrings of length 2: "ab", "ba", "ab"
And it can be shown that there are no special substrings with a length of at least three. So the answer would be 4 + 3 = 7.
l r
a b c d a
Constraints:
1 <= s.length <= 10^5
s consists of lowercase English letters