[Leet Code] Build an Array With Stack Operations

Problem:

Given an array `target` and an integer `n`. In each iteration, you will read a number from `list = {1,2,3..., n}`.

Build the `target` array using the following operations:

[Leet Code] Relative Ranks

Problem:

You are given an integer array `score` of size `n`, where `score[i]` is the score of the `ith` athlete in a competition. All the scores are guaranteed to be unique.

The athletes are placed based on their scores, where the `1st` place athlete has the highest score…

[Leet Code] Search Insert Position

Problem:

Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You must write an algorithm with `O(log n)` runtime complexity.

Example 1:

`Input…`

Problem:

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

Suppose…

[Leet Code] Binary Search

Problem:

Given an array of integers `nums` which is sorted in ascending order, and an integer `target`, write a function to search `target` in `nums`. If `target` exists, then return its index. Otherwise, return `-1`.

You must write an algorithm with `O(log n)` runtime complexity.

Example 1:

`Input…`

[Leet Code] Determine Color of a Chessboard Square

Problem:

You are given `coordinates`, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.

Return `true` if the square is white, and `false` if the square is black.

The coordinate will always represent a valid chessboard square. The…

[Leet Code] Final Value of Variable After Performing Operations

Problem:

There is a programming language with only four operations and one variable `X`:

Initially, the value of `X` is `0`.

Given an array…

[Leet Code] Reverse Vowels of a String

Problem:

Given a string `s`, reverse only all the vowels in the string and return it.

The vowels are `'a'`, `'e'`, `'i'`, `'o'`, and `'u'`, and they can appear in both cases.

Example 1:

`Input: s = "hello"Output: "holle"`

Example 2:

`Input: s = "leetcode"Output: "leotcede"`

Solution:

`class Solution(object):    def reverseVowels(self, s):        """        :type s: str        :rtype: str        """        vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]        if s == "":            return ""        s = list(s)        ending = len(s) -1        starting = 0        while starting < ending:            if s[starting] in vowels:                if s[ending] in vowels:                    temp = s[starting]                    s[starting] = s[ending]                    s[ending] = temp                    starting += 1                    ending -= 1                else:                    ending -= 1            elif s[ending] in vowels and s[starting] not in vowels:                starting +=1             else:                starting += 1                ending -= 1         return "".join(s)`

Matthew Boyd

Learning, and posting my findings!

Get the Medium app