Least Number of Perfect Squares that Sums to n

Problem Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not. Examples Example 1: Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4. ...

Linked List in Binary Tree Problem

Problem Given a binary tree root and a linked list with head as the first node. Return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree otherwise return False. In this context downward path means a path that starts at some node and goes downwards. Examples Example 1: ...

Maximum Number of Events That Can Be Attended Problem

Problem You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi. You can attend an event i at any day d where startTimei <= d <= endTimei. You can only attend one event at any time d. Return the maximum number of events you can attend. Examples Example 1: ...

Maximum Size Subarray Sum equals K

Problem Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn’t one, return 0 instead. Note: The sum of the entire nums array is guaranteed to fit within the 32-bit signed integer range. Examples Example 1: Input: nums = [1, -1, 5, -2, 3], k = 3 Output: 4 Explanation: The subarray [1, -1, 5, -2] sums to 3 and is the longest. ...

Odd Even Linked List - Bring odd nodes first and even later

Problem Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on. Note that the relative order inside both the even and odd groups should remain as it was in the input. You must solve the problem in O(1) extra space complexity and O(n) time complexity. ...

Partition List Problem

Problem Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Examples Example 1: --- title: Input --- graph LR A1[1]:::less --> B4[4]:::greater --> C3[3]:::pivot --> D2[2]:::less --> E5[5]:::greater --> F2[2]:::less classDef pivot fill:#ffb6c1,stroke:#000,stroke-width:2px; classDef less fill:#ffcc00,stroke:#000,stroke-width:2px; classDef greater fill:#add8e6,stroke:#000,stroke-width:2px; ...

Partition to K Equal Sum Subsets Problem

Problem Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal. Examples Example 1: Input: nums = [4,3,2,3,5,2,1], k = 4 Output: true Explanation: It is possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums. ...

Populate next pointer to inorder successor in Binary Tree

Problem Given a Binary tree where each node has an extra field (node * next), write a function that puts the inorder successor of that node in the next pointer. struct node { int val; struct node * left; struct node * right; struct node * next; } ...

Populate next pointer to right node in Binary Tree

Provide the Next Siblings Pointers in a Given Binary Tree Problem Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. ...

Reverse Words in a String 2

Reverse Words in a String 2 Problem Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters. The input string does not contain leading or trailing spaces and the words are always separated by a single space. Follow up Could you do it in-place without allocating extra space? Examples Example 1: Input: s = "the sky is blue" Output: "blue is sky the" ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy