forked from RezaSi/go-interview-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution-template.go
More file actions
62 lines (53 loc) · 1.72 KB
/
solution-template.go
File metadata and controls
62 lines (53 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
)
func main() {
// Test cases
testCases := []struct {
nums []int
name string
}{
{[]int{10, 9, 2, 5, 3, 7, 101, 18}, "Example 1"},
{[]int{0, 1, 0, 3, 2, 3}, "Example 2"},
{[]int{7, 7, 7, 7, 7, 7, 7}, "All same numbers"},
{[]int{4, 10, 4, 3, 8, 9}, "Non-trivial example"},
{[]int{}, "Empty array"},
{[]int{5}, "Single element"},
{[]int{5, 4, 3, 2, 1}, "Decreasing order"},
{[]int{1, 2, 3, 4, 5}, "Increasing order"},
}
// Test each approach
for _, tc := range testCases {
fmt.Printf("Test Case: %s\n", tc.name)
fmt.Printf("Input: %v\n", tc.nums)
// Standard dynamic programming approach
dpLength := DPLongestIncreasingSubsequence(tc.nums)
fmt.Printf("DP Solution - LIS Length: %d\n", dpLength)
// Optimized approach
optLength := OptimizedLIS(tc.nums)
fmt.Printf("Optimized Solution - LIS Length: %d\n", optLength)
// Get the actual elements
lisElements := GetLISElements(tc.nums)
fmt.Printf("LIS Elements: %v\n", lisElements)
fmt.Println("-----------------------------------")
}
}
// DPLongestIncreasingSubsequence finds the length of the longest increasing subsequence
// using a standard dynamic programming approach with O(n²) time complexity.
func DPLongestIncreasingSubsequence(nums []int) int {
// TODO: Implement this function
return 0
}
// OptimizedLIS finds the length of the longest increasing subsequence
// using an optimized approach with O(n log n) time complexity.
func OptimizedLIS(nums []int) int {
// TODO: Implement this function
return 0
}
// GetLISElements returns one possible longest increasing subsequence
// (not just the length, but the actual elements).
func GetLISElements(nums []int) []int {
// TODO: Implement this function
return nil
}