You are given a graph that started as a tree with n nodes. One additional edge has been added, creating a cycle. Your task is to find and return the redundant edge that, when removed, would turn the graph back into a tree.
You are given two strings, a and b. You need to find the minimum number of times you should repeat string a so that string b becomes a substring of the repeated a. If it is impossible, return -1.
You are given the root of a binary tree. The task is to find the length of the longest path in the tree where all the nodes in the path have the same value. The path can be anywhere in the tree, not necessarily passing through the root. The path length is determined by the number of edges between the nodes.
You are given an n x n chessboard and a knight that starts at a given position (row, column). The knight moves exactly k times and can randomly choose one of eight possible knight moves at each step. The task is to determine the probability that the knight remains on the board after completing all k moves.
Given a list of words and an integer k, return the k most frequent words in the list. The words should be sorted by their frequency in descending order. If two words have the same frequency, they should be sorted lexicographically.
You are given a binary matrix of size m x n, where 1 represents land and 0 represents water. An island is a group of 1’s connected horizontally or vertically. Return the area of the largest island. If there are no islands, return 0.