Given an array of integers
A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.
1 <= A.length <= 10000
-10000 <= A[i] <= 10000
Ais sorted in non-decreasing order.
First, loop through the given array, and return the squared element. …
In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.If the town judge exists, then:1. The town judge trusts nobody.
2. Everybody (except for the town judge) trusts the town judge.
3. There is exactly one person that satisfies properties 1 and 2.You are given trust, an array of pairs trust[i] = [a, b] representing that the person labelled a trusts the person labelled b.If the town judge exists and can be identified, return the label of the town judge. …
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.
Example output merged tree:
Note: The merging process must start from the root nodes of both trees. …
For our last She’s coding data structure and algorithm event I chose minimum depth of binary tree problem to practice tree traversing with our participants. It can be challenging at first, with the help of depth first search and breadth first search we can solve it easily.
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no children.Example 1: 3
What is Redux-Saga?
Redux-Saga, like Thunk, is a redux middleware for React/Redux application. With the help of Redux-Saga, the side effect becomes easier to manage, more efficient to execute, simple to test and better at handling the failures. It has access to the full redux application state and it can dispatch redux actions. Unlike thunk, its thread can be started, paused and canceled from the main application with normal redux actions.
How do we implement Redux-Saga?
To make the implementation easy to understand, I’ll use my basic React/Redux weather app, to check the 7 days weather forecast of the selected city with the help of One Call API. …
For our last ‘She’s coding’ data structure and algorithm practice event, we chose to solve maximum depth of N-ary tree problem(link). We had interesting discussion about approaches to solve it. In the following blog, I’ll share the common solution to this problem.
Given a n-ary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).
For my last technical interview, I was asked about how to trap rainwater. (Not really 🤪). It was a hard level Leetcode problem. I found it challenging, that’s why I’d like to write a blog about it. To make sure I understand the approach to solve similar problems in the future.
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
It seems like an unsolvable problem, don’t worry, we’ll “tackle” it together.
First, let’s see some key points to consider. The given array is non-negative integers. Thanks to this example image, the width of each bar that represents each element in this array is 1. We need to compute how much blue square the map can contain. Does this help? If not, let’s draw examples to make sure we understand the problem. …
Number of Recent Calls is one of the leetcode questions that tripped us up. (As you can see how many downvotes it has.🧐) In the following blog, I’ll try to explain the problem and the example line by line to make it easier to understand.
Explanation of the question
Write a class
RecentCounter to count recent requests.
The key point above is class, we need to implement a class, not a function.
It has only one method:
ping(int t), where t represents some time in milliseconds.
The class instance needs to have ping method, which is a function that takes t, an integer in the range of
1 <= t <= 10^9 , as an argument. …
Cycle detection is the algorithmic problem of finding a cycle in a sequence of iterated function values, for example, the classic linked list loop detection problem. There are different solution. For the following Leetcode example, I’ll explain true solutions.
head, the head of a linked list, determine if the linked list has a cycle in it.
There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the
next pointer. …