1004. Max Consecutive Ones III

1004. Max Consecutive Ones III Difficulty: Medium Related Topics: Two Pointers, Sliding Window Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of the longest (contiguous) subarray that contains only 1s.  Example 1: Input: A = [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]ContinueContinue reading “1004. Max Consecutive Ones III”

1248. Count Number of Nice Subarrays

567. Permutation in String Difficulty: Medium Related Topics: Two Pointers, Sliding Window Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string. Example 1: Input: s1 = “ab” s2 =ContinueContinue reading “1248. Count Number of Nice Subarrays”

567. Permutation in String

567. Permutation in String Difficulty: Medium Related Topics: Two Pointers, Sliding Window Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string. Example 1: Input: s1 = “ab” s2 =ContinueContinue reading “567. Permutation in String”

1019. Next Greater Node In Linked List

1019. Next Greater Node In Linked List Difficulty: Medium Related Topics: Linked List, Stack We are given a linked list with head as the first node.  Let’s number the nodes in the list: node_1, node_2, node_3, … etc. Each node may have a next larger value: for node_i, next_larger(node_i) is the node_j.val such that j > i, node_j.val > node_i.val,ContinueContinue reading “1019. Next Greater Node In Linked List”

817. Linked List Components

817. Linked List Components Difficulty: Medium Related Topics: Linked List We are given head, the head node of a linked list containing unique integer values. We are also given the list G, a subset of the values in the linked list. Return the number of connected components in G, where two values are connected if they appear consecutively inContinueContinue reading “817. Linked List Components”

725. Split Linked List in Parts

725. Split Linked List in Parts Difficulty: Medium Related Topics: Linked List Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list “parts”. The length of each part should be as equal as possible: no two parts should have a size differing byContinueContinue reading “725. Split Linked List in Parts”

950. Reveal Cards In Increasing Order

950. Reveal Cards In Increasing Order Difficulty: Medium Related Topics: Array In a deck of cards, every card has a unique integer.  You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck. Now, you do the following steps repeatedly, until all cards are revealed: TakeContinueContinue reading “950. Reveal Cards In Increasing Order”

1409. Queries on a Permutation With Key

1409. Queries on a Permutation With Key Difficulty: Medium Related Topics: Array Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules: In the beginning, you have the permutation P=[1,2,3,…,m].For the current i, find the position of queries[i] inContinueContinue reading “1409. Queries on a Permutation With Key”