iOS

Find largest odd Number/Sequence in String

[Question]: In integer string Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string “” if no odd integer exists. A substring is a contiguous sequence of characters within a string. Example 1: Input: num = “52” Output: “5” Explanation: The only non-empty substrings are “5”, “2”, and “52”. “5” is the only odd number input […]

Find largest odd Number/Sequence in String Read More »

 Remove Outermost Parentheses || String

[Question]: A valid parentheses string is either empty “”, “(” + A + “)”, or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, “”, “()”, “(())()”, and “(()(()))” are all valid parentheses strings. Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s. Example 1: Input: s = “(()())(())” Output: “()()()” Explanation: The input string

 Remove Outermost Parentheses || String Read More »

Find a Peak Element (Find Peak Grid in Matrix)

[Question]: A peak element in a 2D matrix is an element that is strictly greater than all of its adjacent neighbour’s to the left, right, top, and bottom. Given a 0-indexed m x n matrix  mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j].You may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell. Write an

Find a Peak Element (Find Peak Grid in Matrix) Read More »

Search a 2D Matrix II (Sorted Matrix)

[Question] : Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Example 1: Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5 Output: true Why Binary Search is not useful for searching in unsorted arrays? The basic condition to apply Binary Search anywhere in any algorithm is

Search a 2D Matrix II (Sorted Matrix) Read More »

Minimize Max Distance to Gas Station

[Question] We have an horizontal number line. On that number line, we have gas stations at positions stations[0], stations[1], …, stations[N-1], where N = size of the stations array. Now, we add K more gas stations so that D, the maximum distance between adjacent gas stations, is minimized. We have to find the smallest possible value of D. Find the answer exactly to 2 decimal

Minimize Max Distance to Gas Station Read More »

Split Array Largest Sum

[Question]: Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split. A subarray is a contiguous part of the array. Example 1: Input: nums = [7,2,5,10,8], k = 2 Output: 18 Explanation: There are four ways to split nums into two subarrays. The

Split Array Largest Sum Read More »