package leetcode

import java.util.*
import kotlin.math.max

/**
 * https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/
 */
class Problem1438 {
    fun longestSubarray(nums: IntArray, limit: Int): Int {
        var answer = 1
        val minDeque = LinkedList<Int>()
        val maxDeque = LinkedList<Int>()
        var left = 0
        for (right in nums.indices) {
            while (minDeque.isNotEmpty() && nums[right] < minDeque.peekLast()) {
                minDeque.pollLast()
            }
            minDeque.addLast(nums[right])
            while (maxDeque.isNotEmpty() && nums[right] > maxDeque.peekLast()) {
                maxDeque.pollLast()
            }
            maxDeque.addLast(nums[right])
            while (maxDeque.peekFirst() - minDeque.peekFirst() > limit) {
                if (minDeque.peekFirst() == nums[left]) {
                    minDeque.pollFirst()
                }
                if (maxDeque.peekFirst() == nums[left]) {
                    maxDeque.pollFirst()
                }
                left++
            }
            answer = max(answer, right - left + 1)
        }
        return answer
    }
}

Compiled from "Problem1438.kt"
public final class leetcode.Problem1438 {
  public leetcode.Problem1438();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int longestSubarray(int[], int);
    Code:
       0: aload_1
       1: ldc           #15                 // String nums
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_1
       7: istore_3
       8: new           #23                 // class java/util/LinkedList
      11: dup
      12: invokespecial #24                 // Method java/util/LinkedList."<init>":()V
      15: astore        4
      17: new           #23                 // class java/util/LinkedList
      20: dup
      21: invokespecial #24                 // Method java/util/LinkedList."<init>":()V
      24: astore        5
      26: iconst_0
      27: istore        6
      29: iconst_0
      30: istore        7
      32: aload_1
      33: arraylength
      34: istore        8
      36: iload         7
      38: iload         8
      40: if_icmpge     292
      43: aload         4
      45: checkcast     #26                 // class java/util/Collection
      48: invokeinterface #30,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      53: ifne          60
      56: iconst_1
      57: goto          61
      60: iconst_0
      61: ifeq          91
      64: aload_1
      65: iload         7
      67: iaload
      68: aload         4
      70: invokevirtual #34                 // Method java/util/LinkedList.peekLast:()Ljava/lang/Object;
      73: checkcast     #36                 // class java/lang/Number
      76: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      79: if_icmpge     91
      82: aload         4
      84: invokevirtual #43                 // Method java/util/LinkedList.pollLast:()Ljava/lang/Object;
      87: pop
      88: goto          43
      91: aload         4
      93: aload_1
      94: iload         7
      96: iaload
      97: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     100: invokevirtual #53                 // Method java/util/LinkedList.addLast:(Ljava/lang/Object;)V
     103: aload         5
     105: checkcast     #26                 // class java/util/Collection
     108: invokeinterface #30,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     113: ifne          120
     116: iconst_1
     117: goto          121
     120: iconst_0
     121: ifeq          151
     124: aload_1
     125: iload         7
     127: iaload
     128: aload         5
     130: invokevirtual #34                 // Method java/util/LinkedList.peekLast:()Ljava/lang/Object;
     133: checkcast     #36                 // class java/lang/Number
     136: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     139: if_icmple     151
     142: aload         5
     144: invokevirtual #43                 // Method java/util/LinkedList.pollLast:()Ljava/lang/Object;
     147: pop
     148: goto          103
     151: aload         5
     153: aload_1
     154: iload         7
     156: iaload
     157: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     160: invokevirtual #53                 // Method java/util/LinkedList.addLast:(Ljava/lang/Object;)V
     163: aload         5
     165: invokevirtual #56                 // Method java/util/LinkedList.peekFirst:()Ljava/lang/Object;
     168: checkcast     #36                 // class java/lang/Number
     171: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     174: aload         4
     176: invokevirtual #56                 // Method java/util/LinkedList.peekFirst:()Ljava/lang/Object;
     179: dup
     180: ldc           #58                 // String peekFirst(...)
     182: invokestatic  #61                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     185: checkcast     #36                 // class java/lang/Number
     188: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     191: isub
     192: iload_2
     193: if_icmple     274
     196: aload         4
     198: invokevirtual #56                 // Method java/util/LinkedList.peekFirst:()Ljava/lang/Object;
     201: checkcast     #45                 // class java/lang/Integer
     204: aload_1
     205: iload         6
     207: iaload
     208: istore        9
     210: dup
     211: ifnonnull     218
     214: pop
     215: goto          232
     218: invokevirtual #62                 // Method java/lang/Integer.intValue:()I
     221: iload         9
     223: if_icmpne     232
     226: aload         4
     228: invokevirtual #65                 // Method java/util/LinkedList.pollFirst:()Ljava/lang/Object;
     231: pop
     232: aload         5
     234: invokevirtual #56                 // Method java/util/LinkedList.peekFirst:()Ljava/lang/Object;
     237: checkcast     #45                 // class java/lang/Integer
     240: aload_1
     241: iload         6
     243: iaload
     244: istore        9
     246: dup
     247: ifnonnull     254
     250: pop
     251: goto          268
     254: invokevirtual #62                 // Method java/lang/Integer.intValue:()I
     257: iload         9
     259: if_icmpne     268
     262: aload         5
     264: invokevirtual #65                 // Method java/util/LinkedList.pollFirst:()Ljava/lang/Object;
     267: pop
     268: iinc          6, 1
     271: goto          163
     274: iload_3
     275: iload         7
     277: iload         6
     279: isub
     280: iconst_1
     281: iadd
     282: invokestatic  #71                 // Method java/lang/Math.max:(II)I
     285: istore_3
     286: iinc          7, 1
     289: goto          36
     292: iload_3
     293: ireturn
}


package leetcode

import kotlin.math.max

/**
 * https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences/
 */
class Problem2002 {
    fun maxProduct(s: String): Int {
        return maxProduct(s, 0, "", "")
    }

    private fun maxProduct(s: String, i: Int, word1: String, word2: String): Int {
        if (s.length == i) {
            if (isPalindrome(word1) && isPalindrome(word2)) {
                return word1.length * word2.length
            }
            return 1
        }
        val a = maxProduct(s, i + 1, word1 + s[i], word2)
        val b = maxProduct(s, i + 1, word1, word2 + s[i])
        val c = maxProduct(s, i + 1, word1, word2)
        return max(a, max(b, c))
    }

    private fun isPalindrome(s: String): Boolean {
        var i = 0
        var j = s.length - 1
        while (i < j) {
            if (s[i] != s[j]) {
                return false
            }
            i++
            j--
        }
        return true
    }
}

Compiled from "Problem2002.kt"
public final class leetcode.Problem2002 {
  public leetcode.Problem2002();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int maxProduct(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String s
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_0
       9: ldc           #23                 // String
      11: ldc           #23                 // String
      13: invokespecial #26                 // Method maxProduct:(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)I
      16: ireturn

  private final int maxProduct(java.lang.String, int, java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: invokevirtual #33                 // Method java/lang/String.length:()I
       4: iload_2
       5: if_icmpne     38
       8: aload_0
       9: aload_3
      10: invokespecial #37                 // Method isPalindrome:(Ljava/lang/String;)Z
      13: ifeq          36
      16: aload_0
      17: aload         4
      19: invokespecial #37                 // Method isPalindrome:(Ljava/lang/String;)Z
      22: ifeq          36
      25: aload_3
      26: invokevirtual #33                 // Method java/lang/String.length:()I
      29: aload         4
      31: invokevirtual #33                 // Method java/lang/String.length:()I
      34: imul
      35: ireturn
      36: iconst_1
      37: ireturn
      38: aload_0
      39: aload_1
      40: iload_2
      41: iconst_1
      42: iadd
      43: new           #39                 // class java/lang/StringBuilder
      46: dup
      47: invokespecial #40                 // Method java/lang/StringBuilder."<init>":()V
      50: aload_3
      51: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      54: aload_1
      55: iload_2
      56: invokevirtual #48                 // Method java/lang/String.charAt:(I)C
      59: invokevirtual #51                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      62: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      65: aload         4
      67: invokespecial #26                 // Method maxProduct:(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)I
      70: istore        5
      72: aload_0
      73: aload_1
      74: iload_2
      75: iconst_1
      76: iadd
      77: aload_3
      78: new           #39                 // class java/lang/StringBuilder
      81: dup
      82: invokespecial #40                 // Method java/lang/StringBuilder."<init>":()V
      85: aload         4
      87: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      90: aload_1
      91: iload_2
      92: invokevirtual #48                 // Method java/lang/String.charAt:(I)C
      95: invokevirtual #51                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      98: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     101: invokespecial #26                 // Method maxProduct:(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)I
     104: istore        6
     106: aload_0
     107: aload_1
     108: iload_2
     109: iconst_1
     110: iadd
     111: aload_3
     112: aload         4
     114: invokespecial #26                 // Method maxProduct:(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)I
     117: istore        7
     119: iload         5
     121: iload         6
     123: iload         7
     125: invokestatic  #61                 // Method java/lang/Math.max:(II)I
     128: invokestatic  #61                 // Method java/lang/Math.max:(II)I
     131: ireturn

  private final boolean isPalindrome(java.lang.String);
    Code:
       0: iconst_0
       1: istore_2
       2: aload_1
       3: invokevirtual #33                 // Method java/lang/String.length:()I
       6: iconst_1
       7: isub
       8: istore_3
       9: iload_2
      10: iload_3
      11: if_icmpge     38
      14: aload_1
      15: iload_2
      16: invokevirtual #48                 // Method java/lang/String.charAt:(I)C
      19: aload_1
      20: iload_3
      21: invokevirtual #48                 // Method java/lang/String.charAt:(I)C
      24: if_icmpeq     29
      27: iconst_0
      28: ireturn
      29: iinc          2, 1
      32: iinc          3, -1
      35: goto          9
      38: iconst_1
      39: ireturn
}


package leetcode

/**
 * https://leetcode.com/problems/count-number-of-texts/
 */
class Problem2266 {
    fun countTexts(pressedKeys: String): Int {
        if (pressedKeys.length == 1) {
            return 1
        }
        var answer = 1L
        var i = 0
        var length = 1
        val memo3 = IntArray(pressedKeys.length + 1) { -1 }
        val memo4 = IntArray(pressedKeys.length + 1) { -1 }
        while (i < pressedKeys.length - 1) {
            if (pressedKeys[i] != pressedKeys[i + 1]) {
                val numDigits = numDigits(pressedKeys[i])
                answer = (answer * countTexts(
                    numDigits,
                    length,
                    if (numDigits == 3) memo3 else memo4
                )) % 1_000_000_007
                length = 1
            } else {
                length++
            }
            i++
        }
        val numDigits = numDigits(pressedKeys[i])
        answer = (answer * countTexts(
            numDigits,
            length,
            if (numDigits == 3) memo3 else memo4
        )) % 1_000_000_007
        return answer.toInt()
    }

    private fun numDigits(key: Char): Int {
        return if (key == '7' || key == '9') 4 else 3
    }

    private fun countTexts(numDigits: Int, length: Int, memo: IntArray): Int {
        if (length < 0) {
            return 0
        }
        if (length == 0) {
            return 1
        }
        if (memo[length] != -1) {
            return memo[length]
        }
        var count = 0
        for (digit in 1..numDigits) {
            count = (count + countTexts(numDigits, length - digit, memo)) % 1_000_000_007
        }
        memo[length] = count
        return count
    }
}

Compiled from "Problem2266.kt"
public final class leetcode.Problem2266 {
  public leetcode.Problem2266();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int countTexts(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String pressedKeys
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #27                 // Method java/lang/String.length:()I
      10: iconst_1
      11: if_icmpne     16
      14: iconst_1
      15: ireturn
      16: lconst_1
      17: lstore_2
      18: iconst_0
      19: istore        4
      21: iconst_1
      22: istore        5
      24: iconst_0
      25: istore        7
      27: aload_1
      28: invokevirtual #27                 // Method java/lang/String.length:()I
      31: iconst_1
      32: iadd
      33: istore        8
      35: iload         8
      37: newarray       int
      39: astore        9
      41: iload         7
      43: iload         8
      45: if_icmpge     64
      48: iload         7
      50: istore        10
      52: aload         9
      54: iload         10
      56: iconst_m1
      57: iastore
      58: iinc          7, 1
      61: goto          41
      64: aload         9
      66: astore        6
      68: iconst_0
      69: istore        8
      71: aload_1
      72: invokevirtual #27                 // Method java/lang/String.length:()I
      75: iconst_1
      76: iadd
      77: istore        9
      79: iload         9
      81: newarray       int
      83: astore        10
      85: iload         8
      87: iload         9
      89: if_icmpge     108
      92: iload         8
      94: istore        11
      96: aload         10
      98: iload         11
     100: iconst_m1
     101: iastore
     102: iinc          8, 1
     105: goto          85
     108: aload         10
     110: astore        7
     112: iload         4
     114: aload_1
     115: invokevirtual #27                 // Method java/lang/String.length:()I
     118: iconst_1
     119: isub
     120: if_icmpge     199
     123: aload_1
     124: iload         4
     126: invokevirtual #31                 // Method java/lang/String.charAt:(I)C
     129: aload_1
     130: iload         4
     132: iconst_1
     133: iadd
     134: invokevirtual #31                 // Method java/lang/String.charAt:(I)C
     137: if_icmpeq     187
     140: aload_0
     141: aload_1
     142: iload         4
     144: invokevirtual #31                 // Method java/lang/String.charAt:(I)C
     147: invokespecial #35                 // Method numDigits:(C)I
     150: istore        8
     152: lload_2
     153: aload_0
     154: iload         8
     156: iload         5
     158: iload         8
     160: iconst_3
     161: if_icmpne     169
     164: aload         6
     166: goto          171
     169: aload         7
     171: invokespecial #38                 // Method countTexts:(II[I)I
     174: i2l
     175: lmul
     176: ldc           #39                 // int 1000000007
     178: i2l
     179: lrem
     180: lstore_2
     181: iconst_1
     182: istore        5
     184: goto          193
     187: iload         5
     189: iinc          5, 1
     192: pop
     193: iinc          4, 1
     196: goto          112
     199: aload_0
     200: aload_1
     201: iload         4
     203: invokevirtual #31                 // Method java/lang/String.charAt:(I)C
     206: invokespecial #35                 // Method numDigits:(C)I
     209: istore        8
     211: lload_2
     212: aload_0
     213: iload         8
     215: iload         5
     217: iload         8
     219: iconst_3
     220: if_icmpne     228
     223: aload         6
     225: goto          230
     228: aload         7
     230: invokespecial #38                 // Method countTexts:(II[I)I
     233: i2l
     234: lmul
     235: ldc           #39                 // int 1000000007
     237: i2l
     238: lrem
     239: lstore_2
     240: lload_2
     241: l2i
     242: ireturn

  private final int numDigits(char);
    Code:
       0: iload_1
       1: tableswitch   { // 55 to 57
                    55: 28
                    56: 32
                    57: 28
               default: 32
          }
      28: iconst_4
      29: goto          33
      32: iconst_3
      33: ireturn

  private final int countTexts(int, int, int[]);
    Code:
       0: iload_2
       1: ifge          6
       4: iconst_0
       5: ireturn
       6: iload_2
       7: ifne          12
      10: iconst_1
      11: ireturn
      12: aload_3
      13: iload_2
      14: iaload
      15: iconst_m1
      16: if_icmpeq     23
      19: aload_3
      20: iload_2
      21: iaload
      22: ireturn
      23: iconst_0
      24: istore        4
      26: iconst_1
      27: istore        5
      29: iload         5
      31: iload_1
      32: if_icmpgt     65
      35: iload         4
      37: aload_0
      38: iload_1
      39: iload_2
      40: iload         5
      42: isub
      43: aload_3
      44: invokespecial #38                 // Method countTexts:(II[I)I
      47: iadd
      48: ldc           #39                 // int 1000000007
      50: irem
      51: istore        4
      53: iload         5
      55: iload_1
      56: if_icmpeq     65
      59: iinc          5, 1
      62: goto          35
      65: aload_3
      66: iload_2
      67: iload         4
      69: iastore
      70: iload         4
      72: ireturn
}


package leetcode

/**
 * https://leetcode.com/problems/cyclically-rotating-a-grid/
 */
class Problem1914 {
    fun rotateGrid(grid: Array<IntArray>, k: Int): Array<IntArray> {
        val maxRows: Int = grid.size
        val maxCols: Int = if (grid.isNotEmpty()) grid[0].size else 0
        var row = 0
        var col = 0
        var length = 0
        var height = maxRows
        var width = maxCols
        while (height >= 2 && width >= 2) {
            val perimeter = 2 * (height + width)
            rotateGrid(grid, maxRows, maxCols, length++, row++, col++, k % (perimeter - 4))
            height -= 2
            width -= 2
        }
        return grid
    }

    private fun rotateGrid(grid: Array<IntArray>, maxRows: Int, maxCols: Int, length: Int,
                           row: Int, col: Int, k: Int) {
        var elements = mutableListOf<Int>()
        iterate(maxRows, maxCols, length, row, col) { r, c ->
            elements.add(grid[r][c])
        }
        var index = 0
        var start = false
        var n = 0
        for (i in 0 until elements.size + k) {
            iterate(maxRows, maxCols, length, row, col) { r, c ->
                if (n++ == k) {
                    start = true
                }
                if (start && index < elements.size) {
                    grid[r][c] = elements[index++]
                }
            }
        }
    }

    private fun iterate(maxRows: Int, maxCols: Int, length: Int, row: Int, col: Int,
                        f: (Int, Int) -> Unit) {
        // Go down.
        var r = row
        var c = col
        while (r < maxRows - length) {
            f(r, c)
            r++
        }
        // Go left.
        r--
        c++
        while (c < maxCols - length) {
            f(r, c)
            c++
        }
        // Go up.
        r--
        c--
        while (r >= length) {
            f(r, c)
            r--
        }
        // Go right.
        c--
        r++
        while (c >= length + 1) {
            f(r, c)
            c--
        }
    }
}

Compiled from "Problem1914.kt"
public final class leetcode.Problem1914 {
  public leetcode.Problem1914();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int[][] rotateGrid(int[][], int);
    Code:
       0: aload_1
       1: ldc           #15                 // String grid
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #23                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: istore_3
      12: aload_1
      13: checkcast     #23                 // class "[Ljava/lang/Object;"
      16: arraylength
      17: ifne          24
      20: iconst_1
      21: goto          25
      24: iconst_0
      25: ifne          32
      28: iconst_1
      29: goto          33
      32: iconst_0
      33: ifeq          43
      36: aload_1
      37: iconst_0
      38: aaload
      39: arraylength
      40: goto          44
      43: iconst_0
      44: istore        4
      46: iconst_0
      47: istore        5
      49: iconst_0
      50: istore        6
      52: iconst_0
      53: istore        7
      55: iload_3
      56: istore        8
      58: iload         4
      60: istore        9
      62: iload         8
      64: iconst_2
      65: if_icmplt     121
      68: iload         9
      70: iconst_2
      71: if_icmplt     121
      74: iconst_2
      75: iload         8
      77: iload         9
      79: iadd
      80: imul
      81: istore        10
      83: aload_0
      84: aload_1
      85: iload_3
      86: iload         4
      88: iload         7
      90: iinc          7, 1
      93: iload         5
      95: iinc          5, 1
      98: iload         6
     100: iinc          6, 1
     103: iload_2
     104: iload         10
     106: iconst_4
     107: isub
     108: irem
     109: invokespecial #26                 // Method rotateGrid:([[IIIIIII)V
     112: iinc          8, -2
     115: iinc          9, -2
     118: goto          62
     121: aload_1
     122: areturn

  private final void rotateGrid(int[][], int, int, int, int, int, int);
    Code:
       0: new           #40                 // class kotlin/jvm/internal/Ref$ObjectRef
       3: dup
       4: invokespecial #41                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
       7: astore        8
       9: aload         8
      11: new           #43                 // class java/util/ArrayList
      14: dup
      15: invokespecial #44                 // Method java/util/ArrayList."<init>":()V
      18: checkcast     #46                 // class java/util/List
      21: putfield      #50                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      24: aload_0
      25: iload_2
      26: iload_3
      27: iload         4
      29: iload         5
      31: iload         6
      33: aload         8
      35: aload_1
      36: invokedynamic #70,  0             // InvokeDynamic #0:invoke:(Lkotlin/jvm/internal/Ref$ObjectRef;[[I)Lkotlin/jvm/functions/Function2;
      41: invokespecial #74                 // Method iterate:(IIIIILkotlin/jvm/functions/Function2;)V
      44: new           #76                 // class kotlin/jvm/internal/Ref$IntRef
      47: dup
      48: invokespecial #77                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      51: astore        9
      53: new           #79                 // class kotlin/jvm/internal/Ref$BooleanRef
      56: dup
      57: invokespecial #80                 // Method kotlin/jvm/internal/Ref$BooleanRef."<init>":()V
      60: astore        10
      62: new           #76                 // class kotlin/jvm/internal/Ref$IntRef
      65: dup
      66: invokespecial #77                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      69: astore        11
      71: iconst_0
      72: istore        12
      74: aload         8
      76: getfield      #50                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      79: checkcast     #46                 // class java/util/List
      82: invokeinterface #84,  1           // InterfaceMethod java/util/List.size:()I
      87: iload         7
      89: iadd
      90: istore        13
      92: iload         12
      94: iload         13
      96: if_icmpge     133
      99: aload_0
     100: iload_2
     101: iload_3
     102: iload         4
     104: iload         5
     106: iload         6
     108: aload         11
     110: iload         7
     112: aload         10
     114: aload         9
     116: aload         8
     118: aload_1
     119: invokedynamic #92,  0             // InvokeDynamic #1:invoke:(Lkotlin/jvm/internal/Ref$IntRef;ILkotlin/jvm/internal/Ref$BooleanRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$ObjectRef;[[I)Lkotlin/jvm/functions/Function2;
     124: invokespecial #74                 // Method iterate:(IIIIILkotlin/jvm/functions/Function2;)V
     127: iinc          12, 1
     130: goto          92
     133: return

  private final void iterate(int, int, int, int, int, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.Integer, kotlin.Unit>);
    Code:
       0: iload         4
       2: istore        7
       4: iload         5
       6: istore        8
       8: iload         7
      10: iload_1
      11: iload_3
      12: isub
      13: if_icmpge     40
      16: aload         6
      18: iload         7
      20: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: iload         8
      25: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: invokeinterface #111,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      33: pop
      34: iinc          7, 1
      37: goto          8
      40: iinc          7, -1
      43: iinc          8, 1
      46: iload         8
      48: iload_2
      49: iload_3
      50: isub
      51: if_icmpge     78
      54: aload         6
      56: iload         7
      58: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      61: iload         8
      63: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokeinterface #111,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      71: pop
      72: iinc          8, 1
      75: goto          46
      78: iinc          7, -1
      81: iinc          8, -1
      84: iload         7
      86: iload_3
      87: if_icmplt     114
      90: aload         6
      92: iload         7
      94: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      97: iload         8
      99: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: invokeinterface #111,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     107: pop
     108: iinc          7, -1
     111: goto          84
     114: iinc          8, -1
     117: iinc          7, 1
     120: iload         8
     122: iload_3
     123: iconst_1
     124: iadd
     125: if_icmplt     152
     128: aload         6
     130: iload         7
     132: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     135: iload         8
     137: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     140: invokeinterface #111,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     145: pop
     146: iinc          8, -1
     149: goto          120
     152: return

  private static final kotlin.Unit rotateGrid$lambda$0(kotlin.jvm.internal.Ref$ObjectRef, int[][], int, int);
    Code:
       0: aload_0
       1: getfield      #50                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
       4: checkcast     #46                 // class java/util/List
       7: aload_1
       8: iload_2
       9: aaload
      10: iload_3
      11: iaload
      12: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: invokeinterface #119,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      20: pop
      21: getstatic     #125                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      24: areturn

  private static final kotlin.Unit rotateGrid$lambda$1(kotlin.jvm.internal.Ref$IntRef, int, kotlin.jvm.internal.Ref$BooleanRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$ObjectRef, int[][], int, int);
    Code:
       0: aload_0
       1: getfield      #129                // Field kotlin/jvm/internal/Ref$IntRef.element:I
       4: istore        8
       6: aload_0
       7: iload         8
       9: iconst_1
      10: iadd
      11: putfield      #129                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      14: iload         8
      16: iload_1
      17: if_icmpne     25
      20: aload_2
      21: iconst_1
      22: putfield      #132                // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
      25: aload_2
      26: getfield      #132                // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
      29: ifeq          95
      32: aload_3
      33: getfield      #129                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      36: aload         4
      38: getfield      #50                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      41: checkcast     #46                 // class java/util/List
      44: invokeinterface #84,  1           // InterfaceMethod java/util/List.size:()I
      49: if_icmpge     95
      52: aload         5
      54: iload         6
      56: aaload
      57: iload         7
      59: aload         4
      61: getfield      #50                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      64: checkcast     #46                 // class java/util/List
      67: aload_3
      68: getfield      #129                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      71: istore        8
      73: aload_3
      74: iload         8
      76: iconst_1
      77: iadd
      78: putfield      #129                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      81: iload         8
      83: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #138                // class java/lang/Number
      91: invokevirtual #141                // Method java/lang/Number.intValue:()I
      94: iastore
      95: getstatic     #125                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      98: areturn
}


package leetcode

import kotlin.math.max
import kotlin.math.min

/**
 * https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/
 */
class Problem1482 {
    fun minDays(bloomDay: IntArray, m: Int, k: Int): Int {
        if (bloomDay.size < m * k) {
            return -1
        }
        var min = Int.MAX_VALUE
        var max = Int.MIN_VALUE
        for (day in bloomDay) {
            min = min(min, day)
            max = max(max, day)
        }
        while (min <= max) {
            val mid = min + ((max - min) / 2)
            if (isValid(bloomDay, m, k, mid)) {
                max = mid - 1
            } else {
                min = mid + 1
            }
        }
        return min
    }

    private fun isValid(bloomDay: IntArray, m: Int, k: Int, day: Int): Boolean {
        var bouquets = 0
        var flowers = 0
        for (d in bloomDay) {
            if (d > day) {
                flowers = 0
            } else {
                flowers++
            }
            if (flowers == k) {
                flowers = 0
                bouquets++
            }
            if (bouquets == m) {
                return true
            }
        }
        return false
    }
}

Compiled from "Problem1482.kt"
public final class leetcode.Problem1482 {
  public leetcode.Problem1482();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int minDays(int[], int, int);
    Code:
       0: aload_1
       1: ldc           #15                 // String bloomDay
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: arraylength
       8: iload_2
       9: iload_3
      10: imul
      11: if_icmpge     16
      14: iconst_m1
      15: ireturn
      16: ldc           #22                 // int 2147483647
      18: istore        4
      20: ldc           #23                 // int -2147483648
      22: istore        5
      24: iconst_0
      25: istore        6
      27: aload_1
      28: arraylength
      29: istore        7
      31: iload         6
      33: iload         7
      35: if_icmpge     68
      38: aload_1
      39: iload         6
      41: iaload
      42: istore        8
      44: iload         4
      46: iload         8
      48: invokestatic  #29                 // Method java/lang/Math.min:(II)I
      51: istore        4
      53: iload         5
      55: iload         8
      57: invokestatic  #32                 // Method java/lang/Math.max:(II)I
      60: istore        5
      62: iinc          6, 1
      65: goto          31
      68: iload         4
      70: iload         5
      72: if_icmpgt     117
      75: iload         4
      77: iload         5
      79: iload         4
      81: isub
      82: iconst_2
      83: idiv
      84: iadd
      85: istore        6
      87: aload_0
      88: aload_1
      89: iload_2
      90: iload_3
      91: iload         6
      93: invokespecial #36                 // Method isValid:([IIII)Z
      96: ifeq          108
      99: iload         6
     101: iconst_1
     102: isub
     103: istore        5
     105: goto          68
     108: iload         6
     110: iconst_1
     111: iadd
     112: istore        4
     114: goto          68
     117: iload         4
     119: ireturn

  private final boolean isValid(int[], int, int, int);
    Code:
       0: iconst_0
       1: istore        5
       3: iconst_0
       4: istore        6
       6: iconst_0
       7: istore        7
       9: aload_1
      10: arraylength
      11: istore        8
      13: iload         7
      15: iload         8
      17: if_icmpge     71
      20: aload_1
      21: iload         7
      23: iaload
      24: istore        9
      26: iload         9
      28: iload         4
      30: if_icmple     39
      33: iconst_0
      34: istore        6
      36: goto          45
      39: iload         6
      41: iinc          6, 1
      44: pop
      45: iload         6
      47: iload_3
      48: if_icmpne     57
      51: iconst_0
      52: istore        6
      54: iinc          5, 1
      57: iload         5
      59: iload_2
      60: if_icmpne     65
      63: iconst_1
      64: ireturn
      65: iinc          7, 1
      68: goto          13
      71: iconst_0
      72: ireturn
}


package leetcode

import kotlin.math.max

/**
 * https://leetcode.com/problems/largest-magic-square/
 */
class Problem1895 {
    fun largestMagicSquare(grid: Array<IntArray>): Int {
        val maxRow = grid.size
        val maxCol = if (maxRow > 0) grid[0].size else 0
        val rowSums = Array(maxRow) { IntArray(maxCol) }
        val colSums = Array(maxRow) { IntArray(maxCol) }
        val rightDiagonalSums =  Array(maxRow) { IntArray(maxCol) }
        val leftDiagonalSums =  Array(maxRow) { IntArray(maxCol) }
        for (row in 0 until maxRow) {
            for (col in 0 until maxCol) {
                // Direction: --
                rowSums[row][col] = if (col == 0) {
                    grid[row][col]
                } else {
                    rowSums[row][col - 1] + grid[row][col]
                }
                // Direction: |
                colSums[row][col] = if (row == 0) {
                    grid[row][col]
                } else {
                    colSums[row - 1][col] + grid[row][col]
                }
                // Direction: \
                rightDiagonalSums[row][col] = if (row == 0 || col == 0) {
                    grid[row][col]
                } else {
                    rightDiagonalSums[row - 1][col - 1] + grid[row][col]
                }
                // Direction: /
                leftDiagonalSums[row][col] = if (row == 0 || col == maxCol - 1) {
                    grid[row][col]
                } else {
                    leftDiagonalSums[row - 1][col + 1] + grid[row][col]
                }
            }
        }
        var answer = 1
        for (row in 0 until maxRow) {
            for (col in 0 until maxCol) {
                var k = 1
                while (row + k <= maxRow && col + k <= maxCol) {
                    if (isMagicSquare(rowSums, colSums, leftDiagonalSums, rightDiagonalSums,
                            row, col, k)) {
                        answer = max(answer, k)
                    }
                    k++
                }
            }
        }
        return answer
    }

    private fun isMagicSquare(rowSums: Array<IntArray>,
                              colSums: Array<IntArray>,
                              leftDiagonalSums: Array<IntArray>,
                              rightDiagonalSums: Array<IntArray>,
                              row: Int, col: Int, size: Int): Boolean {
        val maxRow = rowSums.size
        val maxCol = if (maxRow > 0) rowSums[0].size else 0
        var sum = 0
        for (r in row until row + size) {
            val rowSum = rowSums[r][col + size - 1] - (if (col - 1 >= 0) rowSums[r][col - 1] else 0)
            if (sum == 0) {
                sum = rowSum
            } else {
                if (sum != rowSum) {
                    return false
                }
            }
        }
        for (c in col until col + size) {
            val colSum = colSums[row + size - 1][c] - (if (row - 1 >= 0) colSums[row - 1][c] else 0)
            if (sum != colSum) {
                return false
            }
        }
        val rightDiagonalSum = rightDiagonalSums[row + size - 1][col + size - 1] -
                (if (row - 1 >= 0 && col - 1 >= 0) rightDiagonalSums[row - 1][col - 1] else 0)
        if (sum != rightDiagonalSum) {
            return false
        }
        val leftDiagonalSum = leftDiagonalSums[row + size - 1][col] -
                (if (row - 1 >= 0 && col + size < maxCol) leftDiagonalSums[row - 1][col + size] else 0)
        if (sum != leftDiagonalSum) {
            return false
        }
        return true
    }
}

Compiled from "Problem1895.kt"
public final class leetcode.Problem1895 {
  public leetcode.Problem1895();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int largestMagicSquare(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String grid
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #23                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: istore_2
      12: iload_2
      13: ifle          23
      16: aload_1
      17: iconst_0
      18: aaload
      19: arraylength
      20: goto          24
      23: iconst_0
      24: istore_3
      25: iconst_0
      26: istore        5
      28: iload_2
      29: anewarray     #25                 // class "[I"
      32: astore        6
      34: iload         5
      36: iload_2
      37: if_icmpge     58
      40: iload         5
      42: istore        7
      44: aload         6
      46: iload         7
      48: iload_3
      49: newarray       int
      51: aastore
      52: iinc          5, 1
      55: goto          34
      58: aload         6
      60: astore        4
      62: iconst_0
      63: istore        6
      65: iload_2
      66: anewarray     #25                 // class "[I"
      69: astore        7
      71: iload         6
      73: iload_2
      74: if_icmpge     95
      77: iload         6
      79: istore        8
      81: aload         7
      83: iload         8
      85: iload_3
      86: newarray       int
      88: aastore
      89: iinc          6, 1
      92: goto          71
      95: aload         7
      97: astore        5
      99: iconst_0
     100: istore        7
     102: iload_2
     103: anewarray     #25                 // class "[I"
     106: astore        8
     108: iload         7
     110: iload_2
     111: if_icmpge     132
     114: iload         7
     116: istore        9
     118: aload         8
     120: iload         9
     122: iload_3
     123: newarray       int
     125: aastore
     126: iinc          7, 1
     129: goto          108
     132: aload         8
     134: astore        6
     136: iconst_0
     137: istore        8
     139: iload_2
     140: anewarray     #25                 // class "[I"
     143: astore        9
     145: iload         8
     147: iload_2
     148: if_icmpge     169
     151: iload         8
     153: istore        10
     155: aload         9
     157: iload         10
     159: iload_3
     160: newarray       int
     162: aastore
     163: iinc          8, 1
     166: goto          145
     169: aload         9
     171: astore        7
     173: iconst_0
     174: istore        8
     176: iload         8
     178: iload_2
     179: if_icmpge     384
     182: iconst_0
     183: istore        9
     185: iload         9
     187: iload_3
     188: if_icmpge     378
     191: aload         4
     193: iload         8
     195: aaload
     196: iload         9
     198: iload         9
     200: ifne          213
     203: aload_1
     204: iload         8
     206: aaload
     207: iload         9
     209: iaload
     210: goto          231
     213: aload         4
     215: iload         8
     217: aaload
     218: iload         9
     220: iconst_1
     221: isub
     222: iaload
     223: aload_1
     224: iload         8
     226: aaload
     227: iload         9
     229: iaload
     230: iadd
     231: iastore
     232: aload         5
     234: iload         8
     236: aaload
     237: iload         9
     239: iload         8
     241: ifne          254
     244: aload_1
     245: iload         8
     247: aaload
     248: iload         9
     250: iaload
     251: goto          272
     254: aload         5
     256: iload         8
     258: iconst_1
     259: isub
     260: aaload
     261: iload         9
     263: iaload
     264: aload_1
     265: iload         8
     267: aaload
     268: iload         9
     270: iaload
     271: iadd
     272: iastore
     273: aload         6
     275: iload         8
     277: aaload
     278: iload         9
     280: iload         8
     282: ifeq          290
     285: iload         9
     287: ifne          300
     290: aload_1
     291: iload         8
     293: aaload
     294: iload         9
     296: iaload
     297: goto          320
     300: aload         6
     302: iload         8
     304: iconst_1
     305: isub
     306: aaload
     307: iload         9
     309: iconst_1
     310: isub
     311: iaload
     312: aload_1
     313: iload         8
     315: aaload
     316: iload         9
     318: iaload
     319: iadd
     320: iastore
     321: aload         7
     323: iload         8
     325: aaload
     326: iload         9
     328: iload         8
     330: ifeq          341
     333: iload         9
     335: iload_3
     336: iconst_1
     337: isub
     338: if_icmpne     351
     341: aload_1
     342: iload         8
     344: aaload
     345: iload         9
     347: iaload
     348: goto          371
     351: aload         7
     353: iload         8
     355: iconst_1
     356: isub
     357: aaload
     358: iload         9
     360: iconst_1
     361: iadd
     362: iaload
     363: aload_1
     364: iload         8
     366: aaload
     367: iload         9
     369: iaload
     370: iadd
     371: iastore
     372: iinc          9, 1
     375: goto          185
     378: iinc          8, 1
     381: goto          176
     384: iconst_1
     385: istore        8
     387: iconst_0
     388: istore        9
     390: iload         9
     392: iload_2
     393: if_icmpge     474
     396: iconst_0
     397: istore        10
     399: iload         10
     401: iload_3
     402: if_icmpge     468
     405: iconst_1
     406: istore        11
     408: iload         9
     410: iload         11
     412: iadd
     413: iload_2
     414: if_icmpgt     462
     417: iload         10
     419: iload         11
     421: iadd
     422: iload_3
     423: if_icmpgt     462
     426: aload_0
     427: aload         4
     429: aload         5
     431: aload         7
     433: aload         6
     435: iload         9
     437: iload         10
     439: iload         11
     441: invokespecial #29                 // Method isMagicSquare:([[I[[I[[I[[IIII)Z
     444: ifeq          456
     447: iload         8
     449: iload         11
     451: invokestatic  #35                 // Method java/lang/Math.max:(II)I
     454: istore        8
     456: iinc          11, 1
     459: goto          408
     462: iinc          10, 1
     465: goto          399
     468: iinc          9, 1
     471: goto          390
     474: iload         8
     476: ireturn

  private final boolean isMagicSquare(int[][], int[][], int[][], int[][], int, int, int);
    Code:
       0: aload_1
       1: checkcast     #23                 // class "[Ljava/lang/Object;"
       4: arraylength
       5: istore        8
       7: iload         8
       9: ifle          19
      12: aload_1
      13: iconst_0
      14: aaload
      15: arraylength
      16: goto          20
      19: iconst_0
      20: istore        9
      22: iconst_0
      23: istore        10
      25: iload         5
      27: istore        11
      29: iload         5
      31: iload         7
      33: iadd
      34: istore        12
      36: iload         11
      38: iload         12
      40: if_icmpge     105
      43: aload_1
      44: iload         11
      46: aaload
      47: iload         6
      49: iload         7
      51: iadd
      52: iconst_1
      53: isub
      54: iaload
      55: iload         6
      57: iconst_1
      58: isub
      59: iflt          74
      62: aload_1
      63: iload         11
      65: aaload
      66: iload         6
      68: iconst_1
      69: isub
      70: iaload
      71: goto          75
      74: iconst_0
      75: isub
      76: istore        13
      78: iload         10
      80: ifne          90
      83: iload         13
      85: istore        10
      87: goto          99
      90: iload         10
      92: iload         13
      94: if_icmpeq     99
      97: iconst_0
      98: ireturn
      99: iinc          11, 1
     102: goto          36
     105: iload         6
     107: istore        11
     109: iload         6
     111: iload         7
     113: iadd
     114: istore        12
     116: iload         11
     118: iload         12
     120: if_icmpge     173
     123: aload_2
     124: iload         5
     126: iload         7
     128: iadd
     129: iconst_1
     130: isub
     131: aaload
     132: iload         11
     134: iaload
     135: iload         5
     137: iconst_1
     138: isub
     139: iflt          154
     142: aload_2
     143: iload         5
     145: iconst_1
     146: isub
     147: aaload
     148: iload         11
     150: iaload
     151: goto          155
     154: iconst_0
     155: isub
     156: istore        13
     158: iload         10
     160: iload         13
     162: if_icmpeq     167
     165: iconst_0
     166: ireturn
     167: iinc          11, 1
     170: goto          116
     173: aload         4
     175: iload         5
     177: iload         7
     179: iadd
     180: iconst_1
     181: isub
     182: aaload
     183: iload         6
     185: iload         7
     187: iadd
     188: iconst_1
     189: isub
     190: iaload
     191: iload         5
     193: iconst_1
     194: isub
     195: iflt          220
     198: iload         6
     200: iconst_1
     201: isub
     202: iflt          220
     205: aload         4
     207: iload         5
     209: iconst_1
     210: isub
     211: aaload
     212: iload         6
     214: iconst_1
     215: isub
     216: iaload
     217: goto          221
     220: iconst_0
     221: isub
     222: istore        11
     224: iload         10
     226: iload         11
     228: if_icmpeq     233
     231: iconst_0
     232: ireturn
     233: aload_3
     234: iload         5
     236: iload         7
     238: iadd
     239: iconst_1
     240: isub
     241: aaload
     242: iload         6
     244: iaload
     245: iload         5
     247: iconst_1
     248: isub
     249: iflt          277
     252: iload         6
     254: iload         7
     256: iadd
     257: iload         9
     259: if_icmpge     277
     262: aload_3
     263: iload         5
     265: iconst_1
     266: isub
     267: aaload
     268: iload         6
     270: iload         7
     272: iadd
     273: iaload
     274: goto          278
     277: iconst_0
     278: isub
     279: istore        12
     281: iload         10
     283: iload         12
     285: if_icmpeq     290
     288: iconst_0
     289: ireturn
     290: iconst_1
     291: ireturn
}


package leetcode

import java.lang.Integer.max
import java.util.*

/**
 * https://leetcode.com/problems/the-time-when-the-network-becomes-idle/
 */
class Problem2039 {
    fun networkBecomesIdle(edges: Array<IntArray>, patience: IntArray): Int {
        val adjList = buildAdjList(edges)
        val queue = LinkedList<Int>()
        val visited = mutableSetOf<Int>()
        val edgeTo = mutableMapOf<Int, Int>()
        val counts = mutableMapOf<Int, Int>()
        queue.add(0)
        while (!queue.isEmpty()) {
            val current = queue.remove()
            if (current in visited) {
                continue
            }
            visited.add(current)
            val neighbors = adjList[current]
            if (neighbors != null) {
                for (neighbor in neighbors) {
                    if (neighbor in visited) {
                        continue
                    }
                    if (neighbor !in edgeTo) {
                        edgeTo[neighbor] = current
                        counts[neighbor] = (counts[current] ?: 0) + 1
                    }
                    queue.add(neighbor)
                }
            }
        }
        var answer = 0
        for (i in 1 until adjList.size) {
            val time = counts[i]!! * 2
            answer = max(answer, (time + (((time - 1) / patience[i]) * patience[i])) + 1)
        }
        return answer
    }

    private fun buildAdjList(edges: Array<IntArray>): Map<Int, List<Int>> {
        val map = mutableMapOf<Int, MutableList<Int>>()
        for (edge in edges) {
            val list1 = map[edge[0]] ?: mutableListOf()
            list1 += edge[1]
            map[edge[0]] = list1
            val list2 = map[edge[1]] ?: mutableListOf()
            list2 += edge[0]
            map[edge[1]] = list2
        }
        return map
    }
}

Compiled from "Problem2039.kt"
public final class leetcode.Problem2039 {
  public leetcode.Problem2039();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int networkBecomesIdle(int[][], int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String edges
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String patience
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokespecial #27                 // Method buildAdjList:([[I)Ljava/util/Map;
      17: astore_3
      18: new           #29                 // class java/util/LinkedList
      21: dup
      22: invokespecial #30                 // Method java/util/LinkedList."<init>":()V
      25: astore        4
      27: new           #32                 // class java/util/LinkedHashSet
      30: dup
      31: invokespecial #33                 // Method java/util/LinkedHashSet."<init>":()V
      34: checkcast     #35                 // class java/util/Set
      37: astore        5
      39: new           #37                 // class java/util/LinkedHashMap
      42: dup
      43: invokespecial #38                 // Method java/util/LinkedHashMap."<init>":()V
      46: checkcast     #40                 // class java/util/Map
      49: astore        6
      51: new           #37                 // class java/util/LinkedHashMap
      54: dup
      55: invokespecial #38                 // Method java/util/LinkedHashMap."<init>":()V
      58: checkcast     #40                 // class java/util/Map
      61: astore        7
      63: aload         4
      65: iconst_0
      66: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      69: invokevirtual #50                 // Method java/util/LinkedList.add:(Ljava/lang/Object;)Z
      72: pop
      73: aload         4
      75: invokevirtual #54                 // Method java/util/LinkedList.isEmpty:()Z
      78: ifne          294
      81: aload         4
      83: invokevirtual #58                 // Method java/util/LinkedList.remove:()Ljava/lang/Object;
      86: checkcast     #42                 // class java/lang/Integer
      89: astore        8
      91: aload         5
      93: aload         8
      95: invokeinterface #61,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     100: ifeq          106
     103: goto          73
     106: aload         5
     108: aload         8
     110: invokestatic  #65                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     113: aload         8
     115: invokeinterface #66,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     120: pop
     121: aload_3
     122: aload         8
     124: invokeinterface #70,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     129: checkcast     #72                 // class java/util/List
     132: astore        9
     134: aload         9
     136: ifnull        73
     139: aload         9
     141: invokeinterface #76,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     146: astore        10
     148: aload         10
     150: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifeq          73
     158: aload         10
     160: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     165: checkcast     #86                 // class java/lang/Number
     168: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     171: istore        11
     173: aload         5
     175: iload         11
     177: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     180: invokeinterface #61,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     185: ifeq          191
     188: goto          148
     191: iload         11
     193: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     196: aload         6
     198: swap
     199: invokeinterface #93,  2           // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     204: ifne          280
     207: iload         11
     209: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     212: astore        13
     214: aload         6
     216: aload         13
     218: aload         8
     220: invokeinterface #97,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     225: pop
     226: aload         7
     228: astore        12
     230: iload         11
     232: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     235: astore        13
     237: aload         7
     239: aload         8
     241: invokeinterface #70,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     246: checkcast     #42                 // class java/lang/Integer
     249: dup
     250: ifnull        259
     253: invokevirtual #98                 // Method java/lang/Integer.intValue:()I
     256: goto          261
     259: pop
     260: iconst_0
     261: iconst_1
     262: iadd
     263: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     266: astore        14
     268: aload         12
     270: aload         13
     272: aload         14
     274: invokeinterface #97,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     279: pop
     280: aload         4
     282: iload         11
     284: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     287: invokevirtual #50                 // Method java/util/LinkedList.add:(Ljava/lang/Object;)Z
     290: pop
     291: goto          148
     294: iconst_0
     295: istore        8
     297: iconst_1
     298: istore        9
     300: aload_3
     301: invokeinterface #101,  1          // InterfaceMethod java/util/Map.size:()I
     306: istore        10
     308: iload         9
     310: iload         10
     312: if_icmpge     373
     315: aload         7
     317: iload         9
     319: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     322: invokeinterface #70,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     327: dup
     328: invokestatic  #65                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     331: checkcast     #86                 // class java/lang/Number
     334: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     337: iconst_2
     338: imul
     339: istore        11
     341: iload         8
     343: iload         11
     345: iload         11
     347: iconst_1
     348: isub
     349: aload_2
     350: iload         9
     352: iaload
     353: idiv
     354: aload_2
     355: iload         9
     357: iaload
     358: imul
     359: iadd
     360: iconst_1
     361: iadd
     362: invokestatic  #105                // Method java/lang/Integer.max:(II)I
     365: istore        8
     367: iinc          9, 1
     370: goto          308
     373: iload         8
     375: ireturn

  private final java.util.Map<java.lang.Integer, java.util.List<java.lang.Integer>> buildAdjList(int[][]);
    Code:
       0: new           #37                 // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #38                 // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #40                 // class java/util/Map
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: checkcast     #129                // class "[Ljava/lang/Object;"
      17: arraylength
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     171
      26: aload_1
      27: iload_3
      28: aaload
      29: astore        5
      31: aload_2
      32: aload         5
      34: iconst_0
      35: iaload
      36: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: invokeinterface #70,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      44: checkcast     #72                 // class java/util/List
      47: dup
      48: ifnonnull     62
      51: pop
      52: new           #131                // class java/util/ArrayList
      55: dup
      56: invokespecial #132                // Method java/util/ArrayList."<init>":()V
      59: checkcast     #72                 // class java/util/List
      62: astore        6
      64: aload         6
      66: checkcast     #134                // class java/util/Collection
      69: aload         5
      71: iconst_1
      72: iaload
      73: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: invokeinterface #135,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      81: pop
      82: aload_2
      83: aload         5
      85: iconst_0
      86: iaload
      87: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: aload         6
      92: invokeinterface #97,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      97: pop
      98: aload_2
      99: aload         5
     101: iconst_1
     102: iaload
     103: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: invokeinterface #70,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     111: checkcast     #72                 // class java/util/List
     114: dup
     115: ifnonnull     129
     118: pop
     119: new           #131                // class java/util/ArrayList
     122: dup
     123: invokespecial #132                // Method java/util/ArrayList."<init>":()V
     126: checkcast     #72                 // class java/util/List
     129: astore        7
     131: aload         7
     133: checkcast     #134                // class java/util/Collection
     136: aload         5
     138: iconst_0
     139: iaload
     140: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: invokeinterface #135,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     148: pop
     149: aload_2
     150: aload         5
     152: iconst_1
     153: iaload
     154: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     157: aload         7
     159: invokeinterface #97,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     164: pop
     165: iinc          3, 1
     168: goto          20
     171: aload_2
     172: areturn
}


package leetcode

/**
 * https://leetcode.com/problems/course-schedule-iv/
 */
class Problem1462 {
    fun checkIfPrerequisite(numCourses: Int, prerequisites: Array<IntArray>,
                            queries: Array<IntArray>): List<Boolean> {
        val adjList = buildAdjList(prerequisites)
        val dependencyMap = mutableMapOf<Int, MutableSet<Int>>()
        for (course in 0 until numCourses) {
            val dependencies = mutableSetOf<Int>()
            dfs(adjList, BooleanArray(numCourses), dependencies, course)
            dependencyMap[course] = dependencies
        }
        val answer = mutableListOf<Boolean>()
        for (query in queries) {
            answer += query[1] in dependencyMap[query[0]]!!
        }
        return answer
    }

    private fun buildAdjList(prerequisites: Array<IntArray>): Map<Int, List<Int>> {
        val adjList = mutableMapOf<Int, MutableList<Int>>()
        for (prerequisite in prerequisites) {
            val from = prerequisite[0]
            val to = prerequisite[1]
            val list = adjList[from] ?: mutableListOf()
            list += to
            adjList[from] = list
        }
        return adjList
    }

    private fun dfs(adjList: Map<Int, List<Int>>, visited: BooleanArray,
                    dependencies: MutableSet<Int>, course: Int) {
        visited[course] = true
        for (adj in (adjList[course] ?: listOf())) {
            if (!visited[adj]) {
                dfs(adjList, visited, dependencies, adj)
            }
        }
        dependencies += course
    }
}

Compiled from "Problem1462.kt"
public final class leetcode.Problem1462 {
  public leetcode.Problem1462();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.util.List<java.lang.Boolean> checkIfPrerequisite(int, int[][], int[][]);
    Code:
       0: aload_2
       1: ldc           #16                 // String prerequisites
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #24                 // String queries
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_2
      14: invokespecial #28                 // Method buildAdjList:([[I)Ljava/util/Map;
      17: astore        4
      19: new           #30                 // class java/util/LinkedHashMap
      22: dup
      23: invokespecial #31                 // Method java/util/LinkedHashMap."<init>":()V
      26: checkcast     #33                 // class java/util/Map
      29: astore        5
      31: iconst_0
      32: istore        6
      34: iload         6
      36: iload_1
      37: if_icmpge     90
      40: new           #35                 // class java/util/LinkedHashSet
      43: dup
      44: invokespecial #36                 // Method java/util/LinkedHashSet."<init>":()V
      47: checkcast     #38                 // class java/util/Set
      50: astore        7
      52: aload_0
      53: aload         4
      55: iload_1
      56: newarray       boolean
      58: aload         7
      60: iload         6
      62: invokespecial #42                 // Method dfs:(Ljava/util/Map;[ZLjava/util/Set;I)V
      65: iload         6
      67: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      70: astore        9
      72: aload         5
      74: aload         9
      76: aload         7
      78: invokeinterface #52,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      83: pop
      84: iinc          6, 1
      87: goto          34
      90: new           #54                 // class java/util/ArrayList
      93: dup
      94: invokespecial #55                 // Method java/util/ArrayList."<init>":()V
      97: checkcast     #57                 // class java/util/List
     100: astore        6
     102: iconst_0
     103: istore        7
     105: aload_3
     106: checkcast     #59                 // class "[Ljava/lang/Object;"
     109: arraylength
     110: istore        8
     112: iload         7
     114: iload         8
     116: if_icmpge     178
     119: aload_3
     120: iload         7
     122: aaload
     123: astore        9
     125: aload         6
     127: checkcast     #61                 // class java/util/Collection
     130: aload         5
     132: aload         9
     134: iconst_0
     135: iaload
     136: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     139: invokeinterface #65,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     144: dup
     145: invokestatic  #69                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     148: checkcast     #38                 // class java/util/Set
     151: aload         9
     153: iconst_1
     154: iaload
     155: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     158: invokeinterface #73,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     163: invokestatic  #78                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     166: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     171: pop
     172: iinc          7, 1
     175: goto          112
     178: aload         6
     180: areturn

  private final java.util.Map<java.lang.Integer, java.util.List<java.lang.Integer>> buildAdjList(int[][]);
    Code:
       0: new           #30                 // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #31                 // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #33                 // class java/util/Map
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: checkcast     #59                 // class "[Ljava/lang/Object;"
      17: arraylength
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     118
      26: aload_1
      27: iload_3
      28: aaload
      29: astore        5
      31: aload         5
      33: iconst_0
      34: iaload
      35: istore        6
      37: aload         5
      39: iconst_1
      40: iaload
      41: istore        7
      43: aload_2
      44: iload         6
      46: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokeinterface #65,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      54: checkcast     #57                 // class java/util/List
      57: dup
      58: ifnonnull     72
      61: pop
      62: new           #54                 // class java/util/ArrayList
      65: dup
      66: invokespecial #55                 // Method java/util/ArrayList."<init>":()V
      69: checkcast     #57                 // class java/util/List
      72: astore        8
      74: iload         7
      76: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: astore        9
      81: aload         8
      83: checkcast     #61                 // class java/util/Collection
      86: aload         9
      88: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: iload         6
      96: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: astore        9
     101: aload_2
     102: aload         9
     104: aload         8
     106: invokeinterface #52,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     111: pop
     112: iinc          3, 1
     115: goto          20
     118: aload_2
     119: areturn

  private final void dfs(java.util.Map<java.lang.Integer, ? extends java.util.List<java.lang.Integer>>, boolean[], java.util.Set<java.lang.Integer>, int);
    Code:
       0: aload_2
       1: iload         4
       3: iconst_1
       4: bastore
       5: aload_1
       6: iload         4
       8: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      11: invokeinterface #65,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      16: checkcast     #57                 // class java/util/List
      19: dup
      20: ifnonnull     27
      23: pop
      24: invokestatic  #108                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      27: invokeinterface #112,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      32: astore        5
      34: aload         5
      36: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          78
      44: aload         5
      46: invokeinterface #122,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: checkcast     #124                // class java/lang/Number
      54: invokevirtual #128                // Method java/lang/Number.intValue:()I
      57: istore        6
      59: aload_2
      60: iload         6
      62: baload
      63: ifne          34
      66: aload_0
      67: aload_1
      68: aload_2
      69: aload_3
      70: iload         6
      72: invokespecial #42                 // Method dfs:(Ljava/util/Map;[ZLjava/util/Set;I)V
      75: goto          34
      78: iload         4
      80: invokestatic  #48                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      83: astore        6
      85: aload_3
      86: checkcast     #61                 // class java/util/Collection
      89: aload         6
      91: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      96: pop
      97: return
}


package leetcode

/**
 * https://leetcode.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/
 */
class Problem1604 {
    fun alertNames(keyName: Array<String>, keyTime: Array<String>): List<String> {
        val map = mutableMapOf<String, MutableList<String>>()
        for (i in keyName.indices) {
            val times = map[keyName[i]] ?: mutableListOf()
            times += keyTime[i]
            map[keyName[i]] = times
        }
        val answer = mutableListOf<String>()
        for ((key, value) in map) {
            var i = 0
            value.sort()
            while (i < value.size - 2) {
                val t = difference(value[i], value[i + 1]) + difference(value[i + 1], value[i + 2])
                if (t <= 60) {
                    answer += key
                    break
                }
                i++
            }
        }
        answer.sort()
        return answer
    }

    private fun difference(from: String, to: String): Int {
        val (fromHour, fromMinute) = from.split(":")
        val (toHour, toMinute) = to.split(":")
        val minute = toMinute.toInt() - fromMinute.toInt()
        val hour = (toHour.toInt() - fromHour.toInt()) * 60
        return minute + hour
    }
}

Compiled from "Problem1604.kt"
public final class leetcode.Problem1604 {
  public leetcode.Problem1604();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.util.List<java.lang.String> alertNames(java.lang.String[], java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #16                 // String keyName
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #24                 // String keyTime
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #26                 // class java/util/LinkedHashMap
      15: dup
      16: invokespecial #27                 // Method java/util/LinkedHashMap."<init>":()V
      19: checkcast     #29                 // class java/util/Map
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_1
      27: arraylength
      28: istore        5
      30: iload         4
      32: iload         5
      34: if_icmpge     101
      37: aload_3
      38: aload_1
      39: iload         4
      41: aaload
      42: invokeinterface #33,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      47: checkcast     #35                 // class java/util/List
      50: dup
      51: ifnonnull     65
      54: pop
      55: new           #37                 // class java/util/ArrayList
      58: dup
      59: invokespecial #38                 // Method java/util/ArrayList."<init>":()V
      62: checkcast     #35                 // class java/util/List
      65: astore        6
      67: aload         6
      69: checkcast     #40                 // class java/util/Collection
      72: aload_2
      73: iload         4
      75: aaload
      76: invokeinterface #44,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      81: pop
      82: aload_3
      83: aload_1
      84: iload         4
      86: aaload
      87: aload         6
      89: invokeinterface #48,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      94: pop
      95: iinc          4, 1
      98: goto          30
     101: new           #37                 // class java/util/ArrayList
     104: dup
     105: invokespecial #38                 // Method java/util/ArrayList."<init>":()V
     108: checkcast     #35                 // class java/util/List
     111: astore        4
     113: aload_3
     114: invokeinterface #52,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     119: invokeinterface #58,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     124: astore        5
     126: aload         5
     128: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     133: ifeq          288
     136: aload         5
     138: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     143: checkcast     #70                 // class java/util/Map$Entry
     146: astore        6
     148: aload         6
     150: invokeinterface #73,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     155: checkcast     #75                 // class java/lang/String
     158: astore        7
     160: aload         6
     162: invokeinterface #78,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     167: checkcast     #35                 // class java/util/List
     170: astore        8
     172: iconst_0
     173: istore        9
     175: aload         8
     177: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
     180: iload         9
     182: aload         8
     184: invokeinterface #88,  1           // InterfaceMethod java/util/List.size:()I
     189: iconst_2
     190: isub
     191: if_icmpge     126
     194: aload_0
     195: aload         8
     197: iload         9
     199: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     204: checkcast     #75                 // class java/lang/String
     207: aload         8
     209: iload         9
     211: iconst_1
     212: iadd
     213: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #75                 // class java/lang/String
     221: invokespecial #95                 // Method difference:(Ljava/lang/String;Ljava/lang/String;)I
     224: aload_0
     225: aload         8
     227: iload         9
     229: iconst_1
     230: iadd
     231: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     236: checkcast     #75                 // class java/lang/String
     239: aload         8
     241: iload         9
     243: iconst_2
     244: iadd
     245: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     250: checkcast     #75                 // class java/lang/String
     253: invokespecial #95                 // Method difference:(Ljava/lang/String;Ljava/lang/String;)I
     256: iadd
     257: istore        10
     259: iload         10
     261: bipush        60
     263: if_icmpgt     282
     266: aload         4
     268: checkcast     #40                 // class java/util/Collection
     271: aload         7
     273: invokeinterface #44,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     278: pop
     279: goto          126
     282: iinc          9, 1
     285: goto          180
     288: aload         4
     290: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
     293: aload         4
     295: areturn

  private final int difference(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #110                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #75                 // class java/lang/String
       8: astore        4
      10: aload         4
      12: iconst_0
      13: ldc           #112                // String :
      15: aastore
      16: aload         4
      18: iconst_0
      19: iconst_0
      20: bipush        6
      22: aconst_null
      23: invokestatic  #118                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      26: astore_3
      27: aload_3
      28: iconst_0
      29: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: checkcast     #75                 // class java/lang/String
      37: astore        4
      39: aload_3
      40: iconst_1
      41: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      46: checkcast     #75                 // class java/lang/String
      49: astore        5
      51: aload_2
      52: checkcast     #110                // class java/lang/CharSequence
      55: iconst_1
      56: anewarray     #75                 // class java/lang/String
      59: astore        7
      61: aload         7
      63: iconst_0
      64: ldc           #112                // String :
      66: aastore
      67: aload         7
      69: iconst_0
      70: iconst_0
      71: bipush        6
      73: aconst_null
      74: invokestatic  #118                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      77: astore        6
      79: aload         6
      81: iconst_0
      82: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      87: checkcast     #75                 // class java/lang/String
      90: astore        7
      92: aload         6
      94: iconst_1
      95: invokeinterface #91,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     100: checkcast     #75                 // class java/lang/String
     103: astore        8
     105: aload         8
     107: invokestatic  #124                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     110: aload         5
     112: invokestatic  #124                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     115: isub
     116: istore        9
     118: aload         7
     120: invokestatic  #124                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     123: aload         4
     125: invokestatic  #124                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     128: isub
     129: bipush        60
     131: imul
     132: istore        10
     134: iload         9
     136: iload         10
     138: iadd
     139: ireturn
}


package leetcode

/**
 * https://leetcode.com/problems/detect-cycles-in-2d-grid/
 */
class Problem1559 {
    fun containsCycle(grid: Array<CharArray>): Boolean {
        val maxRow = grid.size
        val maxCol = if (maxRow == 0) 0 else grid[0].size
        val visited = Array(grid.size) { BooleanArray(maxCol) }
        var row = 0
        while (row < maxRow) {
            var col = 0
            while (col < maxCol) {
                if (visited[row][col]) {
                    col++
                    continue
                }
                if (containsCycle(grid, maxRow, maxCol, grid[row][col], visited, -1, -1, row, col)) {
                    return true
                }
                col++
            }
            row++
        }
        return false
    }

    private fun containsCycle(grid: Array<CharArray>, maxRow: Int, maxCol: Int, char: Char,
                              visited: Array<BooleanArray>, previousRow: Int, previousCol: Int,
                              currentRow: Int, currentCol: Int): Boolean {

        if (visited[currentRow][currentCol]) {
            return false
        }
        visited[currentRow][currentCol] = true
        for ((r, c) in arrayOf(intArrayOf(1, 0), intArrayOf(-1, 0), intArrayOf(0, 1), intArrayOf(0, -1))) {
            val newRow = currentRow + r
            val newCol = currentCol + c
            if (newRow < 0 || newRow == maxRow || newCol < 0 || newCol == maxCol) {
                continue
            }
            if (grid[newRow][newCol] != char) {
                continue
            }
            if (!(previousRow == newRow && previousCol == newCol)) {
                if (visited[newRow][newCol]) {
                    return true
                }
                if (containsCycle(
                        grid, maxRow, maxCol, char, visited, currentRow, currentCol,
                        newRow, newCol
                    )
                ) {
                    return true
                }
            }
        }
        return false
    }
}

Compiled from "Problem1559.kt"
public final class leetcode.Problem1559 {
  public leetcode.Problem1559();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final boolean containsCycle(char[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String grid
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #23                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: istore_2
      12: iload_2
      13: ifne          20
      16: iconst_0
      17: goto          24
      20: aload_1
      21: iconst_0
      22: aaload
      23: arraylength
      24: istore_3
      25: iconst_0
      26: istore        5
      28: aload_1
      29: checkcast     #23                 // class "[Ljava/lang/Object;"
      32: arraylength
      33: istore        6
      35: iload         6
      37: anewarray     #25                 // class "[Z"
      40: astore        7
      42: iload         5
      44: iload         6
      46: if_icmpge     67
      49: iload         5
      51: istore        8
      53: aload         7
      55: iload         8
      57: iload_3
      58: newarray       boolean
      60: aastore
      61: iinc          5, 1
      64: goto          42
      67: aload         7
      69: astore        4
      71: iconst_0
      72: istore        5
      74: iload         5
      76: iload_2
      77: if_icmpge     145
      80: iconst_0
      81: istore        6
      83: iload         6
      85: iload_3
      86: if_icmpge     139
      89: aload         4
      91: iload         5
      93: aaload
      94: iload         6
      96: baload
      97: ifeq          106
     100: iinc          6, 1
     103: goto          83
     106: aload_0
     107: aload_1
     108: iload_2
     109: iload_3
     110: aload_1
     111: iload         5
     113: aaload
     114: iload         6
     116: caload
     117: aload         4
     119: iconst_m1
     120: iconst_m1
     121: iload         5
     123: iload         6
     125: invokespecial #28                 // Method containsCycle:([[CIIC[[ZIIII)Z
     128: ifeq          133
     131: iconst_1
     132: ireturn
     133: iinc          6, 1
     136: goto          83
     139: iinc          5, 1
     142: goto          74
     145: iconst_0
     146: ireturn

  private final boolean containsCycle(char[][], int, int, char, boolean[][], int, int, int, int);
    Code:
       0: aload         5
       2: iload         8
       4: aaload
       5: iload         9
       7: baload
       8: ifeq          13
      11: iconst_0
      12: ireturn
      13: aload         5
      15: iload         8
      17: aaload
      18: iload         9
      20: iconst_1
      21: bastore
      22: iconst_4
      23: anewarray     #40                 // class "[I"
      26: astore        11
      28: aload         11
      30: iconst_0
      31: iconst_2
      32: newarray       int
      34: astore        12
      36: aload         12
      38: iconst_0
      39: iconst_1
      40: iastore
      41: aload         12
      43: iconst_1
      44: iconst_0
      45: iastore
      46: aload         12
      48: aastore
      49: aload         11
      51: iconst_1
      52: iconst_2
      53: newarray       int
      55: astore        12
      57: aload         12
      59: iconst_0
      60: iconst_m1
      61: iastore
      62: aload         12
      64: iconst_1
      65: iconst_0
      66: iastore
      67: aload         12
      69: aastore
      70: aload         11
      72: iconst_2
      73: iconst_2
      74: newarray       int
      76: astore        12
      78: aload         12
      80: iconst_0
      81: iconst_0
      82: iastore
      83: aload         12
      85: iconst_1
      86: iconst_1
      87: iastore
      88: aload         12
      90: aastore
      91: aload         11
      93: iconst_3
      94: iconst_2
      95: newarray       int
      97: astore        12
      99: aload         12
     101: iconst_0
     102: iconst_0
     103: iastore
     104: aload         12
     106: iconst_1
     107: iconst_m1
     108: iastore
     109: aload         12
     111: aastore
     112: aload         11
     114: astore        10
     116: iconst_0
     117: istore        11
     119: aload         10
     121: checkcast     #23                 // class "[Ljava/lang/Object;"
     124: arraylength
     125: istore        12
     127: iload         11
     129: iload         12
     131: if_icmpge     264
     134: aload         10
     136: iload         11
     138: aaload
     139: astore        13
     141: aload         13
     143: iconst_0
     144: iaload
     145: istore        14
     147: aload         13
     149: iconst_1
     150: iaload
     151: istore        15
     153: iload         8
     155: iload         14
     157: iadd
     158: istore        16
     160: iload         9
     162: iload         15
     164: iadd
     165: istore        17
     167: iload         16
     169: iflt          189
     172: iload         16
     174: iload_2
     175: if_icmpeq     189
     178: iload         17
     180: iflt          189
     183: iload         17
     185: iload_3
     186: if_icmpne     192
     189: goto          258
     192: aload_1
     193: iload         16
     195: aaload
     196: iload         17
     198: caload
     199: iload         4
     201: if_icmpeq     207
     204: goto          258
     207: iload         6
     209: iload         16
     211: if_icmpne     221
     214: iload         7
     216: iload         17
     218: if_icmpeq     258
     221: aload         5
     223: iload         16
     225: aaload
     226: iload         17
     228: baload
     229: ifeq          234
     232: iconst_1
     233: ireturn
     234: aload_0
     235: aload_1
     236: iload_2
     237: iload_3
     238: iload         4
     240: aload         5
     242: iload         8
     244: iload         9
     246: iload         16
     248: iload         17
     250: invokespecial #28                 // Method containsCycle:([[CIIC[[ZIIII)Z
     253: ifeq          258
     256: iconst_1
     257: ireturn
     258: iinc          11, 1
     261: goto          127
     264: iconst_0
     265: ireturn
}