educative.io

Educative

Is this solution simpler with same runtime, also sliding window?

does this solution have the same runtime & space as the given solution?  

    private fun findSubs(arr: IntArray, sum: Int): List<IntArray> {
            val result = mutableListOf<IntArray>()
            var start = 0
            var end = 0
            var product = 1

            while (start <= end && end < arr.size) {
                val sublist = arr.slice(start..end).toIntArray()
                product *= arr[end]
                if (product < sum) {
                    result.add(sublist)
                }
                if (end < arr.size - 1) {
                    end++
                } else {
                    product = 1
                    start++
                    end = start
                }
            }

            return result
        }

Welcome to the worst community here lol.

1 Like