Skip to content

Latest commit

 

History

82 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kotlin Work

  • Programming exercises done in Kotlin

Entry points

Mainly meant to be used within Intellij, which should be able to give you magic green arrows next to main functions. Run via the gradle wrapper (will even work on Windows!):

gradle wrapper # Setup the wrapper
./gradlew run  # Run a simple hello world

Additionally, use the green run buttons in Intellij. If they disappear, wire the particular class into Main.kt

Contents

Advent of Code

Other solutions for Advent of Code, up to 2022:

Leetcode

Solution to leetcode problems, that passed the tests.
I also try to provide my own tests during development.

To seamlessly run tests for a specific LeetCode problem, simply pass its number to the lctest command:

./kwork.sh test 49
# or
./gradlew lctest 49
Nr. Title Solution Difficulty Time Space Notes
7 Reverse Integer Kotlin Medium O(log(n)) O(1)
20 Valid Parentheses Kotlin Easy O(n) O(n)
36 Valid Sudoku Kotlin Medium O(1) O(1)
49 Group Anagrams Kotlin Medium O(n) O(n)
74 Search a 2D Matrix Kotlin Medium O(log(n+m)) O(1)
128 Longest Consecutive Sequence Kotlin Medium O(n) O(n)
154 Find Minimum in Rotated Sorted Array II Kotlin Hard O(n) O(1)
238 Product of Array Except Self Kotlin Medium O(n) O(n)
347 Top K Frequent Elements Kotlin Medium O(n + k*log(n)) O(n)
396 Rotate Function Kotlin Medium O(n) O(1)
657 Robot Return to Origin Kotlin Easy O(n) O(1)
788 Rotated Digits Kotlin Medium O(n*log(n)) O(1)
796 Rotate String Kotlin Easy O(n) O(n)
974 Subarray Sums Divisible by K Kotlin Medium O(n+k) O(k)
1248 Count Number of Nice Subarrays Kotlin Medium O(n) O(1)
1320 Minimum Distance to Type a Word Using Two Fingers Kotlin Hard O(n) O(1)
1346 Check If N and Its Double Exist Kotlin Easy O(n) O(n)
1559 Detect Cycles in 2D Grid Kotlin Medium O(n*m) O(n*m)
1732 Find the Highest Altitude Kotlin Easy O(n) O(1)
1833 Maximum Ice Cream Bars Kotlin Medium O(n*log(n)) O(n)
1846 Maximum Element After Decreasing and Reararnginge Kotlin Medium O(n*log(n)) O(n)
1855 Maximum Distance Between a Pair of Values Kotlin Medium O(n) O(1)
1914 Cyclically Rotating a Grid Kotlin Medium O(n*m) O(n+m)
2075 2075. Decode the Slanted Ciphertext Kotlin Medium O(n) O(n)
2130 Maximum Twin Sum of a Linked List Kotlin Medium O(n) O(1)
2192 All Ancestors of a Node in a Directed Acyclic Graph Kotlin Medium O(n^2*log(n) + m) O(n^2 + m)
2492 Minimum Score of a Path Between Two Cities Kotlin Medium O(N+E) O(N+E)
2574 Left and right sum differences Kotlin Medium O(n) O(n)
2582 Pass the Pillow Kotlin Easy O(1) O(1)
2770 Maximum Number of Jumps to Reach the Last Index Kotlin Medium O(n^2) O(n)
2839 Check if Strings Can be Made Equal With Operations I Kotlin Easy O(1) O(1)
2840 Check if Strings Can be Made Equal With Operations II Kotlin Medium O(n) O(n)
3464 Maximise the Distance Between Points on a Square Kotlin Hard O(nlog(n) + nlog(side)) O(n)
3741 Minimum Distance Between Three Equal Elements II Kotlin Medium O(n) O(n)
3783 Mirror Distance of an Integer Kotlin Easy O(len(n))a O(1)
3838 Weighted Word Mapping Kotlin Easy O(n) O(n)

Leetcode Metadata Utils

Includes helper code for header comment generation. Run via kwork.sh or directly with Gradle:

# show available CLI flags
./kwork.sh --help                        
./gradlew cli --quiet --args " --help"

# regenerate the table above
./kwork.sh --genProblemTable             
./gradlew cli --quiet --args " -gpt"

# scaffold solution + test for problem 42
./kwork.sh --genFiles --number 42        
./gradlew cli --quiet --args " --genFiles --number 42"

# run tests for problem 49
./kwork.sh test 49                       
./gradlew lctest 49

Misc.

Troubleshooting

Gradle: adding a new executable task

For reasons yet unknown, other internet suggested version of the JavaExec task do not work, as Gradle complains about main and about the classpath.

This one works:

tasks.register<JavaExec>("lcutil") {
    group = "Leetcode Utils"
    mainClass = "lcutils.JavaWorkCLI"
    classpath = sourceSets["main"].runtimeClasspath
}

This, but for:

About

Some algorithmics work done in Kotlin and misc. code

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages