Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 509 Bytes

find-the-most-competitive-subsequence.md

File metadata and controls

29 lines (22 loc) · 509 Bytes

Code

func mostCompetitive(nums []int, k int) []int {
	sol := []int{}
	n_nums := len(nums)

	for i, num := range nums {
		n := len(sol)
		for n > 0 && num < sol[n-1] && n_nums-i+n-1 >= k {
			sol = sol[:n-1]
			n -= 1
		}

		if n < k {
			sol = append(sol, num)
		}

	}

	return sol
}

Solution in mind

  • Solution based off discussion post, given here