Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * You can edit, run, and share this code.
- * play.kotlinlang.org
- */
- fun main() {
- val a = listOf(2,3,9,2,5,1,3,7,10)
- val b = listOf(2,1,3,4,3,10,6,6,1,7,10,10,10)
- val result = mutableListOf<Int>()
- a.forEach { item ->
- val count = b.count { item == it }
- if (!isPrime(count)) {
- result.add(item)
- }
- }
- println(result)
- }
- fun isPrime(num: Int): Boolean {
- if (num < 2) return false
- for (i in 2..num / 2) {
- if (num % i == 0) {
- return false
- }
- }
- return true
- }
- Time complexity:
- If I'm understanding this correctly, the time complexity will be O (n * (m/2))
- Where
- n is the length of list a
- m currently evaluated item from the list a
- Aww it's been a while since I did this O notations thing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement