package com.zer0rez.euler.util

import kotlin.math.sqrt

fun Int.isDivisibleBy(i: Int): Boolean = this % i == 0
fun Int.isDivisibleByAll(i: IntArray): Boolean = i.all { this.isDivisibleBy(it) }

fun Long.isDivisibleBy(i: Long): Boolean = this % i == 0L
fun Long.isDivisibleByAny(i: Collection<Long>): Boolean = i.any { this.isDivisibleBy(it) }

fun Int.isPalindrome(): Boolean {
    if (this < 10) return false;
    val ns = this.toString()
    val end = ns.length - 1
    for (i in 0..(ns.length / 2)) {
        if (i >= end) break
        if (ns[i] != ns[end - i]) return false
    }
    return true
}

fun IntArray.swapin(arrow: Int): Int {
    this[0] = this[1]
    this[1] = arrow
    return this[1]
}

fun fibonacci(quit: (Int) -> Boolean): IntArray {
    var values = ArrayList<Int>()
    values.add(1)
    values.add(1)
    while (!quit(values.last())) {
        values.add(values[values.count() - 1] + values[values.count() - 2])
    }
    values.remove(values.last())
    return values.toIntArray()
}

fun Long.factorize(): Sequence<Long> {
    var target = this
    var current = sqrt(target.toDouble()).toLong()
    return sequence {
        while (current % 2 == 0L) current /= 2
        while (current > 0 && current < target) {
            if (target % current == 0L) {
                yield(current)
                target /= current
            }
            current -= 2
        }
    }
}

fun LongArray.productSeries(size: Int) = IntRange(0, this.count() - size).map { i ->
    Pair(this.slice(i until i + size).reduce { t: Long, x: Long -> x * t }, this.slice(i until i + size))
}

Compiled from "Util.kt"
public final class com.zer0rez.euler.util.UtilKt {
  public static final boolean isDivisibleBy(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: irem
       3: ifne          10
       6: iconst_1
       7: goto          11
      10: iconst_0
      11: ireturn

  public static final boolean isDivisibleByAll(int, int[]);
    Code:
       0: aload_1
       1: ldc           #13                 // String i
       3: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: astore_2
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: aload_2
      14: arraylength
      15: istore        5
      17: iload         4
      19: iload         5
      21: if_icmpge     56
      24: aload_2
      25: iload         4
      27: iaload
      28: istore        6
      30: iload         6
      32: istore        7
      34: iconst_0
      35: istore        8
      37: iload_0
      38: iload         7
      40: invokestatic  #21                 // Method isDivisibleBy:(II)Z
      43: ifne          50
      46: iconst_0
      47: goto          57
      50: iinc          4, 1
      53: goto          17
      56: iconst_1
      57: ireturn

  public static final boolean isDivisibleBy(long, long);
    Code:
       0: lload_0
       1: lload_2
       2: lrem
       3: lconst_0
       4: lcmp
       5: ifne          12
       8: iconst_1
       9: goto          13
      12: iconst_0
      13: ireturn

  public static final boolean isDivisibleByAny(long, java.util.Collection<java.lang.Long>);
    Code:
       0: aload_2
       1: ldc           #13                 // String i
       3: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: checkcast     #36                 // class java/lang/Iterable
      10: astore_3
      11: iconst_0
      12: istore        4
      14: aload_3
      15: checkcast     #38                 // class java/util/Collection
      18: invokeinterface #42,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      23: ifeq          30
      26: iconst_0
      27: goto          84
      30: aload_3
      31: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        5
      38: aload         5
      40: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          83
      48: aload         5
      50: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        6
      57: aload         6
      59: checkcast     #57                 // class java/lang/Number
      62: invokevirtual #61                 // Method java/lang/Number.longValue:()J
      65: lstore        7
      67: iconst_0
      68: istore        9
      70: lload_0
      71: lload         7
      73: invokestatic  #63                 // Method isDivisibleBy:(JJ)Z
      76: ifeq          38
      79: iconst_1
      80: goto          84
      83: iconst_0
      84: ireturn

  public static final boolean isPalindrome(int);
    Code:
       0: iload_0
       1: bipush        10
       3: if_icmpge     8
       6: iconst_0
       7: ireturn
       8: iload_0
       9: invokestatic  #78                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      12: astore_1
      13: aload_1
      14: invokevirtual #82                 // Method java/lang/String.length:()I
      17: iconst_1
      18: isub
      19: istore_2
      20: iconst_0
      21: istore_3
      22: aload_1
      23: invokevirtual #82                 // Method java/lang/String.length:()I
      26: iconst_2
      27: idiv
      28: istore        4
      30: iload_3
      31: iload         4
      33: if_icmpgt     70
      36: iload_3
      37: iload_2
      38: if_icmpge     70
      41: aload_1
      42: iload_3
      43: invokevirtual #86                 // Method java/lang/String.charAt:(I)C
      46: aload_1
      47: iload_2
      48: iload_3
      49: isub
      50: invokevirtual #86                 // Method java/lang/String.charAt:(I)C
      53: if_icmpeq     58
      56: iconst_0
      57: ireturn
      58: iload_3
      59: iload         4
      61: if_icmpeq     70
      64: iinc          3, 1
      67: goto          36
      70: iconst_1
      71: ireturn

  public static final int swapin(int[], int);
    Code:
       0: aload_0
       1: ldc           #94                 // String <this>
       3: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_0
       8: aload_0
       9: iconst_1
      10: iaload
      11: iastore
      12: aload_0
      13: iconst_1
      14: iload_1
      15: iastore
      16: aload_0
      17: iconst_1
      18: iaload
      19: ireturn

  public static final int[] fibonacci(kotlin.jvm.functions.Function1<? super java.lang.Integer, java.lang.Boolean>);
    Code:
       0: aload_0
       1: ldc           #101                // String quit
       3: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #103                // class java/util/ArrayList
       9: dup
      10: invokespecial #107                // Method java/util/ArrayList."<init>":()V
      13: astore_1
      14: aload_1
      15: iconst_1
      16: invokestatic  #112                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: invokevirtual #116                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      22: pop
      23: aload_1
      24: iconst_1
      25: invokestatic  #112                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: invokevirtual #116                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      31: pop
      32: aload_0
      33: aload_1
      34: checkcast     #118                // class java/util/List
      37: invokestatic  #124                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      40: invokeinterface #130,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      45: checkcast     #132                // class java/lang/Boolean
      48: invokevirtual #135                // Method java/lang/Boolean.booleanValue:()Z
      51: ifne          114
      54: aload_1
      55: aload_1
      56: aload_1
      57: checkcast     #38                 // class java/util/Collection
      60: invokeinterface #138,  1          // InterfaceMethod java/util/Collection.size:()I
      65: iconst_1
      66: isub
      67: invokevirtual #142                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      70: checkcast     #57                 // class java/lang/Number
      73: invokevirtual #145                // Method java/lang/Number.intValue:()I
      76: aload_1
      77: aload_1
      78: checkcast     #38                 // class java/util/Collection
      81: invokeinterface #138,  1          // InterfaceMethod java/util/Collection.size:()I
      86: iconst_2
      87: isub
      88: invokevirtual #142                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      91: dup
      92: ldc           #147                // String get(...)
      94: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      97: checkcast     #57                 // class java/lang/Number
     100: invokevirtual #145                // Method java/lang/Number.intValue:()I
     103: iadd
     104: invokestatic  #112                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     107: invokevirtual #116                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     110: pop
     111: goto          32
     114: aload_1
     115: aload_1
     116: checkcast     #118                // class java/util/List
     119: invokestatic  #124                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     122: invokevirtual #153                // Method java/util/ArrayList.remove:(Ljava/lang/Object;)Z
     125: pop
     126: aload_1
     127: checkcast     #38                 // class java/util/Collection
     130: invokestatic  #157                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     133: areturn

  public static final kotlin.sequences.Sequence<java.lang.Long> factorize(long);
    Code:
       0: new           #165                // class kotlin/jvm/internal/Ref$LongRef
       3: dup
       4: invokespecial #166                // Method kotlin/jvm/internal/Ref$LongRef."<init>":()V
       7: astore_2
       8: aload_2
       9: lload_0
      10: putfield      #169                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      13: new           #165                // class kotlin/jvm/internal/Ref$LongRef
      16: dup
      17: invokespecial #166                // Method kotlin/jvm/internal/Ref$LongRef."<init>":()V
      20: astore_3
      21: aload_3
      22: aload_2
      23: getfield      #169                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      26: l2d
      27: invokestatic  #175                // Method java/lang/Math.sqrt:(D)D
      30: d2l
      31: putfield      #169                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      34: new           #177                // class com/zer0rez/euler/util/UtilKt$factorize$1
      37: dup
      38: aload_3
      39: aload_2
      40: aconst_null
      41: invokespecial #180                // Method com/zer0rez/euler/util/UtilKt$factorize$1."<init>":(Lkotlin/jvm/internal/Ref$LongRef;Lkotlin/jvm/internal/Ref$LongRef;Lkotlin/coroutines/Continuation;)V
      44: checkcast     #182                // class kotlin/jvm/functions/Function2
      47: invokestatic  #188                // Method kotlin/sequences/SequencesKt.sequence:(Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence;
      50: areturn

  public static final java.util.List<kotlin.Pair<java.lang.Long, java.util.List<java.lang.Long>>> productSeries(long[], int);
    Code:
       0: aload_0
       1: ldc           #94                 // String <this>
       3: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #197                // class kotlin/ranges/IntRange
       9: dup
      10: iconst_0
      11: aload_0
      12: arraylength
      13: iload_1
      14: isub
      15: invokespecial #200                // Method kotlin/ranges/IntRange."<init>":(II)V
      18: checkcast     #36                 // class java/lang/Iterable
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_2
      25: astore        4
      27: new           #103                // class java/util/ArrayList
      30: dup
      31: aload_2
      32: bipush        10
      34: invokestatic  #204                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      37: invokespecial #207                // Method java/util/ArrayList."<init>":(I)V
      40: checkcast     #38                 // class java/util/Collection
      43: astore        5
      45: iconst_0
      46: istore        6
      48: aload         4
      50: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      55: astore        7
      57: aload         7
      59: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      64: ifeq          240
      67: aload         7
      69: checkcast     #209                // class kotlin/collections/IntIterator
      72: invokevirtual #212                // Method kotlin/collections/IntIterator.nextInt:()I
      75: istore        8
      77: aload         5
      79: iload         8
      81: istore        9
      83: astore        20
      85: iconst_0
      86: istore        10
      88: aload_0
      89: iload         9
      91: iload         9
      93: iload_1
      94: iadd
      95: invokestatic  #218                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      98: invokestatic  #224                // Method kotlin/collections/ArraysKt.slice:([JLkotlin/ranges/IntRange;)Ljava/util/List;
     101: checkcast     #36                 // class java/lang/Iterable
     104: astore        11
     106: iconst_0
     107: istore        12
     109: aload         11
     111: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        13
     118: aload         13
     120: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifne          138
     128: new           #226                // class java/lang/UnsupportedOperationException
     131: dup
     132: ldc           #228                // String Empty collection can\'t be reduced.
     134: invokespecial #231                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     137: athrow
     138: aload         13
     140: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     145: astore        14
     147: aload         13
     149: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          198
     157: aload         14
     159: aload         13
     161: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     166: checkcast     #57                 // class java/lang/Number
     169: invokevirtual #61                 // Method java/lang/Number.longValue:()J
     172: lstore        15
     174: checkcast     #57                 // class java/lang/Number
     177: invokevirtual #61                 // Method java/lang/Number.longValue:()J
     180: lstore        17
     182: iconst_0
     183: istore        19
     185: lload         15
     187: lload         17
     189: lmul
     190: invokestatic  #236                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     193: astore        14
     195: goto          147
     198: aload         14
     200: aload_0
     201: iload         9
     203: iload         9
     205: iload_1
     206: iadd
     207: invokestatic  #218                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     210: invokestatic  #224                // Method kotlin/collections/ArraysKt.slice:([JLkotlin/ranges/IntRange;)Ljava/util/List;
     213: astore        21
     215: astore        22
     217: new           #238                // class kotlin/Pair
     220: dup
     221: aload         22
     223: aload         21
     225: invokespecial #241                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     228: aload         20
     230: swap
     231: invokeinterface #242,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     236: pop
     237: goto          57
     240: aload         5
     242: checkcast     #118                // class java/util/List
     245: nop
     246: areturn
}

Compiled from "Util.kt"
final class com.zer0rez.euler.util.UtilKt$factorize$1 extends kotlin.coroutines.jvm.internal.RestrictedSuspendLambda implements kotlin.jvm.functions.Function2<kotlin.sequences.SequenceScope<? super java.lang.Long>, kotlin.coroutines.Continuation<? super kotlin.Unit>, java.lang.Object> {
  int label;

  private java.lang.Object L$0;

  final kotlin.jvm.internal.Ref$LongRef $current;

  final kotlin.jvm.internal.Ref$LongRef $target;

  com.zer0rez.euler.util.UtilKt$factorize$1(kotlin.jvm.internal.Ref$LongRef, kotlin.jvm.internal.Ref$LongRef, kotlin.coroutines.Continuation<? super com.zer0rez.euler.util.UtilKt$factorize$1>);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
       5: aload_0
       6: aload_2
       7: putfield      #17                 // Field $target:Lkotlin/jvm/internal/Ref$LongRef;
      10: aload_0
      11: iconst_2
      12: aload_3
      13: invokespecial #20                 // Method kotlin/coroutines/jvm/internal/RestrictedSuspendLambda."<init>":(ILkotlin/coroutines/Continuation;)V
      16: return

  public final java.lang.Object invokeSuspend(java.lang.Object);
    Code:
       0: invokestatic  #46                 // Method kotlin/coroutines/intrinsics/IntrinsicsKt.getCOROUTINE_SUSPENDED:()Ljava/lang/Object;
       3: astore_3
       4: aload_0
       5: getfield      #50                 // Field label:I
       8: tableswitch   { // 0 to 1
                     0: 32
                     1: 164
               default: 224
          }
      32: aload_1
      33: invokestatic  #56                 // Method kotlin/ResultKt.throwOnFailure:(Ljava/lang/Object;)V
      36: aload_0
      37: getfield      #59                 // Field L$0:Ljava/lang/Object;
      40: checkcast     #61                 // class kotlin/sequences/SequenceScope
      43: astore_2
      44: aload_0
      45: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
      48: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
      51: iconst_2
      52: i2l
      53: lrem
      54: lconst_0
      55: lcmp
      56: ifne          79
      59: aload_0
      60: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
      63: aload_0
      64: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
      67: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
      70: iconst_2
      71: i2l
      72: ldiv
      73: putfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
      76: goto          44
      79: aload_0
      80: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
      83: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
      86: lconst_0
      87: lcmp
      88: ifle          220
      91: aload_0
      92: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
      95: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
      98: aload_0
      99: getfield      #17                 // Field $target:Lkotlin/jvm/internal/Ref$LongRef;
     102: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     105: lcmp
     106: ifge          220
     109: aload_0
     110: getfield      #17                 // Field $target:Lkotlin/jvm/internal/Ref$LongRef;
     113: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     116: aload_0
     117: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
     120: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     123: lrem
     124: lconst_0
     125: lcmp
     126: ifne          200
     129: aload_2
     130: aload_0
     131: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
     134: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     137: invokestatic  #73                 // Method kotlin/coroutines/jvm/internal/Boxing.boxLong:(J)Ljava/lang/Long;
     140: aload_0
     141: checkcast     #75                 // class kotlin/coroutines/Continuation
     144: aload_0
     145: aload_2
     146: putfield      #59                 // Field L$0:Ljava/lang/Object;
     149: aload_0
     150: iconst_1
     151: putfield      #50                 // Field label:I
     154: invokevirtual #79                 // Method kotlin/sequences/SequenceScope.yield:(Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
     157: dup
     158: aload_3
     159: if_acmpne     177
     162: aload_3
     163: areturn
     164: aload_0
     165: getfield      #59                 // Field L$0:Ljava/lang/Object;
     168: checkcast     #61                 // class kotlin/sequences/SequenceScope
     171: astore_2
     172: aload_1
     173: invokestatic  #56                 // Method kotlin/ResultKt.throwOnFailure:(Ljava/lang/Object;)V
     176: aload_1
     177: pop
     178: aload_0
     179: getfield      #17                 // Field $target:Lkotlin/jvm/internal/Ref$LongRef;
     182: aload_0
     183: getfield      #17                 // Field $target:Lkotlin/jvm/internal/Ref$LongRef;
     186: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     189: aload_0
     190: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
     193: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     196: ldiv
     197: putfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     200: aload_0
     201: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
     204: aload_0
     205: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
     208: getfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     211: iconst_2
     212: i2l
     213: lsub
     214: putfield      #67                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     217: goto          79
     220: getstatic     #85                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     223: areturn
     224: new           #87                 // class java/lang/IllegalStateException
     227: dup
     228: ldc           #89                 // String call to \'resume\' before \'invoke\' with coroutine
     230: invokespecial #92                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     233: athrow

  public final kotlin.coroutines.Continuation<kotlin.Unit> create(java.lang.Object, kotlin.coroutines.Continuation<?>);
    Code:
       0: new           #2                  // class com/zer0rez/euler/util/UtilKt$factorize$1
       3: dup
       4: aload_0
       5: getfield      #14                 // Field $current:Lkotlin/jvm/internal/Ref$LongRef;
       8: aload_0
       9: getfield      #17                 // Field $target:Lkotlin/jvm/internal/Ref$LongRef;
      12: aload_2
      13: invokespecial #101                // Method "<init>":(Lkotlin/jvm/internal/Ref$LongRef;Lkotlin/jvm/internal/Ref$LongRef;Lkotlin/coroutines/Continuation;)V
      16: astore_3
      17: aload_3
      18: aload_1
      19: putfield      #59                 // Field L$0:Ljava/lang/Object;
      22: aload_3
      23: checkcast     #75                 // class kotlin/coroutines/Continuation
      26: areturn

  public final java.lang.Object invoke(kotlin.sequences.SequenceScope<? super java.lang.Long>, kotlin.coroutines.Continuation<? super kotlin.Unit>);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokevirtual #107                // Method create:(Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation;
       6: checkcast     #2                  // class com/zer0rez/euler/util/UtilKt$factorize$1
       9: getstatic     #85                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      12: invokevirtual #109                // Method invokeSuspend:(Ljava/lang/Object;)Ljava/lang/Object;
      15: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #61                 // class kotlin/sequences/SequenceScope
       5: aload_2
       6: checkcast     #75                 // class kotlin/coroutines/Continuation
       9: invokevirtual #114                // Method invoke:(Lkotlin/sequences/SequenceScope;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
      12: areturn
}


package com.leecode.array

/**
 * 一个长度为n-1的递增排序数组中的所有数字都是唯一的，并且每个数字都在范围0～n-1之内。在范围0～n-1内的n个数字中有且只有一个数字不在该数组中，请找出这个数字。
如何在一个1到100的整数数组中找到丢失的数字? google, Amazon,tencent
示例 1:
    输入: [0,1,3]
    输出: 2
示例 2:
    输入: [0,1,2]
    输出: 3
示例 3:
    输入: [0,1,2,3,4,5,6,7,9]
    输出: 8
来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof
 */

/**
 *
 * 直接遍历
 */
fun missingNumber1(nums: IntArray): Int {
    var result: Int = 0
    for (i in nums) {
        if (i != result) {
            break
        }
        result++
    }
    return result
}

/**
 * 二手分查找法
 */
fun missingNumber2(nums: IntArray): Int {
    var start = 0
    var end = nums.size - 1
    if (nums[end] == end) {
        return end + 1
    }
    while (start < end) {
        val mid = (start + end) / 2
        if (nums[mid] != mid) {
            end = mid
        } else {
            start = mid + 1
        }
    }
    return start
}

Compiled from "Code1.kt"
public final class com.leecode.array.Code1Kt {
  public static final int missingNumber1(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: iconst_0
       9: istore_2
      10: aload_0
      11: arraylength
      12: istore_3
      13: iload_2
      14: iload_3
      15: if_icmpge     41
      18: aload_0
      19: iload_2
      20: iaload
      21: istore        4
      23: iload         4
      25: iload_1
      26: if_icmpeq     32
      29: goto          41
      32: iinc          1, 1
      35: iinc          2, 1
      38: goto          13
      41: iload_1
      42: ireturn

  public static final int missingNumber2(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: arraylength
      10: iconst_1
      11: isub
      12: istore_2
      13: aload_0
      14: iload_2
      15: iaload
      16: iload_2
      17: if_icmpne     24
      20: iload_2
      21: iconst_1
      22: iadd
      23: ireturn
      24: iload_1
      25: iload_2
      26: if_icmpge     54
      29: iload_1
      30: iload_2
      31: iadd
      32: iconst_2
      33: idiv
      34: istore_3
      35: aload_0
      36: iload_3
      37: iaload
      38: iload_3
      39: if_icmpeq     47
      42: iload_3
      43: istore_2
      44: goto          24
      47: iload_3
      48: iconst_1
      49: iadd
      50: istore_1
      51: goto          24
      54: iload_1
      55: ireturn
}


package com.leecode.array

/**
找出数组中重复的数字。
在一个长度为 n 的数组 nums 里的所有数字都在 0～n-1 的范围内。数组中某些数字是重复的，但不知道有几个数字重复了，也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。
示例 1：
    输入：[2, 3, 1, 0, 2, 5, 3]
    输出：2 或 3
限制：2 <= n <= 100000
来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof
 */

/**
 * 用一个容器装已经确定的数
 */
fun findRepeatNumber1(nums: IntArray): Int {
    val map = mutableSetOf<Int>()
    for (i in nums) {
        if (map.contains(i)) {
            return i
        } else {
            map.add(i)
        }
    }
    return -1
}

/**
 * 先排序，再判断相邻的数是否相等
 */
fun findRepeatNumber2(nums: IntArray): Int {
    nums.sort()
    for (i in 1 until nums.size) {
        if (nums[i] == nums[i - 1]) {
            return nums[i]
        }
    }
    return -1
}

/**
 * 所有数字都在长度范围内，将每个数字放到对应的下标位置，判断当前数字是否与该位置的数字相等
 */
fun findRepeatNumber3(nums: IntArray): Int {
    for (i in nums.indices) {
        val n = nums[i]
        if (i != n) {
            if (nums[n] == n) {
                return n
            } else {
                nums[i] = nums[n]
                nums[n] = n
            }
        }
    }
    return -1
}

Compiled from "Code2.kt"
public final class com.leecode.array.Code2Kt {
  public static final int findRepeatNumber1(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class java/util/LinkedHashSet
       9: dup
      10: invokespecial #21                 // Method java/util/LinkedHashSet."<init>":()V
      13: checkcast     #23                 // class java/util/Set
      16: astore_1
      17: iconst_0
      18: istore_2
      19: aload_0
      20: arraylength
      21: istore_3
      22: iload_2
      23: iload_3
      24: if_icmpge     67
      27: aload_0
      28: iload_2
      29: iaload
      30: istore        4
      32: aload_1
      33: iload         4
      35: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      38: invokeinterface #33,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      43: ifeq          49
      46: iload         4
      48: ireturn
      49: aload_1
      50: iload         4
      52: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: invokeinterface #36,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      60: pop
      61: iinc          2, 1
      64: goto          22
      67: iconst_m1
      68: ireturn

  public static final int findRepeatNumber2(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #48                 // Method kotlin/collections/ArraysKt.sort:([I)V
      10: iconst_1
      11: istore_1
      12: aload_0
      13: arraylength
      14: istore_2
      15: iload_1
      16: iload_2
      17: if_icmpge     41
      20: aload_0
      21: iload_1
      22: iaload
      23: aload_0
      24: iload_1
      25: iconst_1
      26: isub
      27: iaload
      28: if_icmpne     35
      31: aload_0
      32: iload_1
      33: iaload
      34: ireturn
      35: iinc          1, 1
      38: goto          15
      41: iconst_m1
      42: ireturn

  public static final int findRepeatNumber3(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: arraylength
      10: istore_2
      11: iload_1
      12: iload_2
      13: if_icmpge     50
      16: aload_0
      17: iload_1
      18: iaload
      19: istore_3
      20: iload_1
      21: iload_3
      22: if_icmpeq     44
      25: aload_0
      26: iload_3
      27: iaload
      28: iload_3
      29: if_icmpne     34
      32: iload_3
      33: ireturn
      34: aload_0
      35: iload_1
      36: aload_0
      37: iload_3
      38: iaload
      39: iastore
      40: aload_0
      41: iload_3
      42: iload_3
      43: iastore
      44: iinc          1, 1
      47: goto          11
      50: iconst_m1
      51: ireturn
}


package com.leecode.array

/**
输入一个整数数组，实现一个函数来调整该数组中数字的顺序，使得所有奇数位于数组的前半部分，所有偶数位于数组的后半部分。
示例：
    输入：nums = [1,2,3,4]
    输出：[1,3,2,4]
    注：[3,1,2,4] 也是正确的答案之一。
来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof
 */
/**
 * 申请一个新数组，T(n) ,O(n)
 */
fun exchange1(nums: IntArray): IntArray {
    var start = 0
    var end = nums.size - 1
    val temp = IntArray(nums.size)
    for (i in nums.indices) {
        if (nums[i].and(1) == 1) {
            temp[start++] = nums[i]
        } else {
            temp[end--] = nums[i]
        }
    }
    return temp
}

/**
 * 双指针法，T(n2),O(1)
 * start 从前往后找第一个偶数，end从后往前找最后一个奇数，找到后交换位置
 */
fun exchange2(nums: IntArray): IntArray {
    var start = 0
    var end = nums.size - 1
    var temp: Int
    while (start < end) {
        while (start < end && nums[start].and(1) == 1) {
            start++
        }
        while (start < end && nums[end].and(1) == 0) {
            end--
        }
        if (start < end) {
            temp = nums[start]
            nums[start] = nums[end]
            nums[end] = temp
        }
    }
    return nums
}

/**
 * 快慢指针
 */
fun exchange3(nums: IntArray): IntArray {
    var i = 0
    var j = 0
    var temp: Int
    while (i < nums.size) {
        if (nums[i].and(1) == 1) {
            if (i != j) {
                temp = nums[i]
                nums[i] = nums[j]
                nums[j] = temp
            }
            j++
        }
        i++
    }
    return nums
}

Compiled from "Code3.kt"
public final class com.leecode.array.Code3Kt {
  public static final int[] exchange1(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: arraylength
      10: iconst_1
      11: isub
      12: istore_2
      13: aload_0
      14: arraylength
      15: newarray       int
      17: astore_3
      18: iconst_0
      19: istore        4
      21: aload_0
      22: arraylength
      23: istore        5
      25: iload         4
      27: iload         5
      29: if_icmpge     71
      32: aload_0
      33: iload         4
      35: iaload
      36: iconst_1
      37: iand
      38: iconst_1
      39: if_icmpne     55
      42: aload_3
      43: iload_1
      44: iinc          1, 1
      47: aload_0
      48: iload         4
      50: iaload
      51: iastore
      52: goto          65
      55: aload_3
      56: iload_2
      57: iinc          2, -1
      60: aload_0
      61: iload         4
      63: iaload
      64: iastore
      65: iinc          4, 1
      68: goto          25
      71: aload_3
      72: areturn

  public static final int[] exchange2(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: arraylength
      10: iconst_1
      11: isub
      12: istore_2
      13: iconst_0
      14: istore_3
      15: iload_1
      16: iload_2
      17: if_icmpge     81
      20: iload_1
      21: iload_2
      22: if_icmpge     40
      25: aload_0
      26: iload_1
      27: iaload
      28: iconst_1
      29: iand
      30: iconst_1
      31: if_icmpne     40
      34: iinc          1, 1
      37: goto          20
      40: iload_1
      41: iload_2
      42: if_icmpge     59
      45: aload_0
      46: iload_2
      47: iaload
      48: iconst_1
      49: iand
      50: ifne          59
      53: iinc          2, -1
      56: goto          40
      59: iload_1
      60: iload_2
      61: if_icmpge     15
      64: aload_0
      65: iload_1
      66: iaload
      67: istore_3
      68: aload_0
      69: iload_1
      70: aload_0
      71: iload_2
      72: iaload
      73: iastore
      74: aload_0
      75: iload_2
      76: iload_3
      77: iastore
      78: goto          15
      81: aload_0
      82: areturn

  public static final int[] exchange3(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: iconst_0
       9: istore_2
      10: iconst_0
      11: istore_3
      12: iload_1
      13: aload_0
      14: arraylength
      15: if_icmpge     55
      18: aload_0
      19: iload_1
      20: iaload
      21: iconst_1
      22: iand
      23: iconst_1
      24: if_icmpne     49
      27: iload_1
      28: iload_2
      29: if_icmpeq     46
      32: aload_0
      33: iload_1
      34: iaload
      35: istore_3
      36: aload_0
      37: iload_1
      38: aload_0
      39: iload_2
      40: iaload
      41: iastore
      42: aload_0
      43: iload_2
      44: iload_3
      45: iastore
      46: iinc          2, 1
      49: iinc          1, 1
      52: goto          12
      55: aload_0
      56: areturn
}


package com.leecode.array

/**
给定一个排序数组，你需要在 原地 删除重复出现的元素，使得每个元素只出现一次，返回移除后数组的新长度。
不要使用额外的数组空间，你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。
示例 1:
给定数组 nums = [1,1,2],
函数应该返回新的长度 2, 并且原数组 nums 的前两个元素被修改为 1, 2。
你不需要考虑数组中超出新长度后面的元素。
示例 2:
给定 nums = [0,0,1,1,1,2,2,3,3,4],
函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。
你不需要考虑数组中超出新长度后面的元素。
来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array
 */
fun main() {
    val nums = intArrayOf(0, 0, 1, 1, 1, 2, 2, 3, 3, 4)
    val i = removeDuplicates(nums)
    System.arraycopy(nums, 0, nums, 0, i)
    println(nums.joinToString())
}

fun removeDuplicates(nums: IntArray): Int {
    var i = 0
    var j = 1
    while (j < nums.size) {
        if (nums[i] != nums[j]) {
            i++
            nums[i] = nums[j]
        }
        j++
    }
    return i + 1
}

Compiled from "Code7.kt"
public final class com.leecode.array.Code7Kt {
  public static final void main();
    Code:
       0: bipush        10
       2: newarray       int
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iconst_0
       8: iastore
       9: aload_1
      10: iconst_1
      11: iconst_0
      12: iastore
      13: aload_1
      14: iconst_2
      15: iconst_1
      16: iastore
      17: aload_1
      18: iconst_3
      19: iconst_1
      20: iastore
      21: aload_1
      22: iconst_4
      23: iconst_1
      24: iastore
      25: aload_1
      26: iconst_5
      27: iconst_2
      28: iastore
      29: aload_1
      30: bipush        6
      32: iconst_2
      33: iastore
      34: aload_1
      35: bipush        7
      37: iconst_3
      38: iastore
      39: aload_1
      40: bipush        8
      42: iconst_3
      43: iastore
      44: aload_1
      45: bipush        9
      47: iconst_4
      48: iastore
      49: aload_1
      50: astore_0
      51: aload_0
      52: invokestatic  #10                 // Method removeDuplicates:([I)I
      55: istore_1
      56: aload_0
      57: iconst_0
      58: aload_0
      59: iconst_0
      60: iload_1
      61: invokestatic  #16                 // Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V
      64: aload_0
      65: aconst_null
      66: aconst_null
      67: aconst_null
      68: iconst_0
      69: aconst_null
      70: aconst_null
      71: bipush        63
      73: aconst_null
      74: invokestatic  #22                 // Method kotlin/collections/ArraysKt.joinToString$default:([ILjava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      77: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
      80: swap
      81: invokevirtual #32                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      84: return

  public static final int removeDuplicates(int[]);
    Code:
       0: aload_0
       1: ldc           #38                 // String nums
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: iconst_1
       9: istore_2
      10: iload_2
      11: aload_0
      12: arraylength
      13: if_icmpge     40
      16: aload_0
      17: iload_1
      18: iaload
      19: aload_0
      20: iload_2
      21: iaload
      22: if_icmpeq     34
      25: iinc          1, 1
      28: aload_0
      29: iload_1
      30: aload_0
      31: iload_2
      32: iaload
      33: iastore
      34: iinc          2, 1
      37: goto          10
      40: iload_1
      41: iconst_1
      42: iadd
      43: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #48                 // Method main:()V
       3: return
}


package ctci.arrays_and_strings._02_check_permutation

/**
 * #1.2
 *
 * Check Permutation: Given two strings, write a method to decide if one is a permutation
 * of the other.
 */

class CheckPermutation {

    /**
     * Determines whether two given strings are permutations of each other.
     *
     * Time Complexity: O(n), where n is the length of the input strings.
     *
     * @param string1 The first string to be checked for permutation.
     * @param string2 The second string to be checked for permutation.
     * @return `true` if the strings are permutations, `false` otherwise.
     */
    fun arePermutationsSolutionOne(string1: String, string2: String): Boolean {
        if ((string1.length != string2.length))
            return false

        val charCount = mutableMapOf<Char, Int>()

        string1.forEach {
            charCount[it] = charCount.getOrDefault(it, 0) + 1
        }

        return string2.all {
            charCount[it]?.let { count ->
                count > 0 && charCount.put(it, count - 1) != null
            } ?: false
        }
    }

    /**
     * Time Complexity: O(n), where n is the length of the input strings.
     */
    fun arePermutationsSolutionTwo(string1: String, string2: String): Boolean {
        if (string1.length != string2.length) return false

        return stringToCountMap(string1) == stringToCountMap(string2)
    }

    /**
     * Converts a string into a character count map.
     *
     * This function takes a string as input and creates a mutable map where each character
     * in the string is a key, and the corresponding value is the count of occurrences of that character.
     * It iterates through the characters of the string, updating the count in the map accordingly.
     *
     * @param string The input string to be converted into a character count map.
     * @return A mutable map with characters as keys and their counts as values.
     */
    private fun stringToCountMap(string: String): MutableMap<Char, Int> {
        val charCount = mutableMapOf<Char, Int>()
        string.forEach {
            charCount[it] = charCount.getOrDefault(it, 0) + 1
        }
        return charCount
    }
}

fun main() {
    val string1 = "abc"
    val string2 = "cab"
    val string3 = "bca"
    println("Are $string1 & $string2 Permutations? ${CheckPermutation().arePermutationsSolutionOne(string1, string2)}")
    println("Are $string1 & $string2 Permutations? ${CheckPermutation().arePermutationsSolutionTwo(string1, string2)}")

    println("Are $string2 & $string3 Permutations? ${CheckPermutation().arePermutationsSolutionOne(string2, string3)}")
    println("Are $string2 & $string3 Permutations? ${CheckPermutation().arePermutationsSolutionTwo(string2, string3)}")
}

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

  public final boolean arePermutationsSolutionOne(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String string1
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String string2
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokevirtual #29                 // Method java/lang/String.length:()I
      16: aload_2
      17: invokevirtual #29                 // Method java/lang/String.length:()I
      20: if_icmpeq     25
      23: iconst_0
      24: ireturn
      25: new           #31                 // class java/util/LinkedHashMap
      28: dup
      29: invokespecial #32                 // Method java/util/LinkedHashMap."<init>":()V
      32: checkcast     #34                 // class java/util/Map
      35: astore_3
      36: aload_1
      37: checkcast     #36                 // class java/lang/CharSequence
      40: astore        4
      42: iconst_0
      43: istore        5
      45: iconst_0
      46: istore        6
      48: iload         6
      50: aload         4
      52: invokeinterface #37,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      57: if_icmpge     128
      60: aload         4
      62: iload         6
      64: invokeinterface #41,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      69: istore        7
      71: iload         7
      73: istore        8
      75: iconst_0
      76: istore        9
      78: iload         8
      80: invokestatic  #47                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      83: astore        10
      85: aload_3
      86: aload         10
      88: aload_3
      89: iload         8
      91: invokestatic  #47                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      94: iconst_0
      95: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: invokeinterface #56,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     103: checkcast     #58                 // class java/lang/Number
     106: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     109: iconst_1
     110: iadd
     111: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     119: pop
     120: nop
     121: nop
     122: iinc          6, 1
     125: goto          48
     128: nop
     129: aload_2
     130: checkcast     #36                 // class java/lang/CharSequence
     133: astore        4
     135: iconst_0
     136: istore        5
     138: iconst_0
     139: istore        6
     141: iload         6
     143: aload         4
     145: invokeinterface #37,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     150: if_icmpge     250
     153: aload         4
     155: iload         6
     157: invokeinterface #41,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     162: istore        7
     164: iload         7
     166: istore        8
     168: iconst_0
     169: istore        9
     171: aload_3
     172: iload         8
     174: invokestatic  #47                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     177: invokeinterface #68,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     182: checkcast     #49                 // class java/lang/Integer
     185: dup
     186: ifnull        235
     189: checkcast     #58                 // class java/lang/Number
     192: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     195: istore        10
     197: iconst_0
     198: istore        11
     200: iload         10
     202: ifle          230
     205: aload_3
     206: iload         8
     208: invokestatic  #47                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     211: iload         10
     213: iconst_1
     214: isub
     215: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     218: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     223: ifnull        230
     226: iconst_1
     227: goto          231
     230: iconst_0
     231: nop
     232: goto          237
     235: pop
     236: iconst_0
     237: ifne          244
     240: iconst_0
     241: goto          251
     244: iinc          6, 1
     247: goto          141
     250: iconst_1
     251: ireturn

  public final boolean arePermutationsSolutionTwo(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String string1
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String string2
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokevirtual #29                 // Method java/lang/String.length:()I
      16: aload_2
      17: invokevirtual #29                 // Method java/lang/String.length:()I
      20: if_icmpeq     25
      23: iconst_0
      24: ireturn
      25: aload_0
      26: aload_1
      27: invokespecial #89                 // Method stringToCountMap:(Ljava/lang/String;)Ljava/util/Map;
      30: aload_0
      31: aload_2
      32: invokespecial #89                 // Method stringToCountMap:(Ljava/lang/String;)Ljava/util/Map;
      35: invokestatic  #93                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      38: ireturn

  private final java.util.Map<java.lang.Character, java.lang.Integer> stringToCountMap(java.lang.String);
    Code:
       0: new           #31                 // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #32                 // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #34                 // class java/util/Map
      10: astore_2
      11: aload_1
      12: checkcast     #36                 // class java/lang/CharSequence
      15: astore_3
      16: iconst_0
      17: istore        4
      19: iconst_0
      20: istore        5
      22: iload         5
      24: aload_3
      25: invokeinterface #37,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      30: if_icmpge     100
      33: aload_3
      34: iload         5
      36: invokeinterface #41,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      41: istore        6
      43: iload         6
      45: istore        7
      47: iconst_0
      48: istore        8
      50: iload         7
      52: invokestatic  #47                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      55: astore        9
      57: aload_2
      58: aload         9
      60: aload_2
      61: iload         7
      63: invokestatic  #47                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      66: iconst_0
      67: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      70: invokeinterface #56,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      75: checkcast     #58                 // class java/lang/Number
      78: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      81: iconst_1
      82: iadd
      83: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: invokeinterface #64,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      91: pop
      92: nop
      93: nop
      94: iinc          5, 1
      97: goto          22
     100: nop
     101: aload_2
     102: areturn
}

Compiled from "CheckPermutation.kt"
public final class ctci.arrays_and_strings._02_check_permutation.CheckPermutationKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String abc
       2: astore_0
       3: ldc           #10                 // String cab
       5: astore_1
       6: ldc           #12                 // String bca
       8: astore_2
       9: new           #14                 // class java/lang/StringBuilder
      12: dup
      13: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      16: ldc           #19                 // String Are
      18: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      21: aload_0
      22: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      25: ldc           #25                 // String  &
      27: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      30: aload_1
      31: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      34: ldc           #27                 // String  Permutations?
      36: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      39: new           #29                 // class ctci/arrays_and_strings/_02_check_permutation/CheckPermutation
      42: dup
      43: invokespecial #30                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation."<init>":()V
      46: aload_0
      47: aload_1
      48: invokevirtual #34                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation.arePermutationsSolutionOne:(Ljava/lang/String;Ljava/lang/String;)Z
      51: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
      54: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      57: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
      60: swap
      61: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      64: new           #14                 // class java/lang/StringBuilder
      67: dup
      68: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
      71: ldc           #19                 // String Are
      73: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      76: aload_0
      77: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      80: ldc           #25                 // String  &
      82: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      85: aload_1
      86: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      89: ldc           #27                 // String  Permutations?
      91: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      94: new           #29                 // class ctci/arrays_and_strings/_02_check_permutation/CheckPermutation
      97: dup
      98: invokespecial #30                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation."<init>":()V
     101: aload_0
     102: aload_1
     103: invokevirtual #56                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation.arePermutationsSolutionTwo:(Ljava/lang/String;Ljava/lang/String;)Z
     106: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     109: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     112: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     115: swap
     116: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     119: new           #14                 // class java/lang/StringBuilder
     122: dup
     123: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
     126: ldc           #19                 // String Are
     128: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     131: aload_1
     132: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     135: ldc           #25                 // String  &
     137: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     140: aload_2
     141: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     144: ldc           #27                 // String  Permutations?
     146: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     149: new           #29                 // class ctci/arrays_and_strings/_02_check_permutation/CheckPermutation
     152: dup
     153: invokespecial #30                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation."<init>":()V
     156: aload_1
     157: aload_2
     158: invokevirtual #34                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation.arePermutationsSolutionOne:(Ljava/lang/String;Ljava/lang/String;)Z
     161: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     164: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     167: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     170: swap
     171: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     174: new           #14                 // class java/lang/StringBuilder
     177: dup
     178: invokespecial #17                 // Method java/lang/StringBuilder."<init>":()V
     181: ldc           #19                 // String Are
     183: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     186: aload_1
     187: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     190: ldc           #25                 // String  &
     192: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     195: aload_2
     196: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     199: ldc           #27                 // String  Permutations?
     201: invokevirtual #23                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     204: new           #29                 // class ctci/arrays_and_strings/_02_check_permutation/CheckPermutation
     207: dup
     208: invokespecial #30                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation."<init>":()V
     211: aload_1
     212: aload_2
     213: invokevirtual #56                 // Method ctci/arrays_and_strings/_02_check_permutation/CheckPermutation.arePermutationsSolutionTwo:(Ljava/lang/String;Ljava/lang/String;)Z
     216: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     219: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     222: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     225: swap
     226: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     229: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #63                 // Method main:()V
       3: return
}


package ctci.arrays_and_strings._01_is_unique

/**
 * #1.1
 *
 * Is Unique: Implement an algorithm to determine if a string has all unique characters.
 * What if you can not use additional data structures?
 */

fun main() {
    val string1 = "vishal"
    val string2 = "sehgal"
    val string3 = "linkedin"
    val string4 = "google"

    println("String: $string1 has all unique characters: ${IsUnique().hasUniqueCharactersBetter(string1)}")
    println("String: $string2 has all unique characters: ${IsUnique().hasUniqueCharactersBetter(string2)}")
    println("String: $string3 has all unique characters: ${IsUnique().hasUniqueCharactersBetter(string3)}")
    println("String: $string4 has all unique characters: ${IsUnique().hasUniqueCharactersBetter(string4)}")
    println()
    println("String: $string1 has all unique characters: ${IsUnique().hasUniqueCharactersBest(string1)}")
    println("String: $string2 has all unique characters: ${IsUnique().hasUniqueCharactersBest(string2)}")
    println("String: $string3 has all unique characters: ${IsUnique().hasUniqueCharactersBest(string3)}")
    println("String: $string4 has all unique characters: ${IsUnique().hasUniqueCharactersBetter(string4)}")

}

class IsUnique {

    /**
     * Determines whether a given string has all unique characters.
     *
     * Time complexity: O(n), where n is the length of input string.
     *
     * Here's a breakdown of the time complexity:
     *
     * string.toSet(): This converts the string to a set, which involves iterating through each
     * character in the string to build the set. In the worst case, this operation has a time complexity of O(n),
     * where n is the length of the string.
     *
     * string.length == string.toSet().size: This checks if the length of the original string is equal
     * to the size of the set. The size operation on a set is typically a constant-time operation.
     *
     * Therefore, the dominant factor in determining the time complexity is the conversion of the string
     * to a set, resulting in a total time complexity of O(n), where n is the length of the input string.
     * The function's runtime scales linearly with the size of the input.
     *
     *
     * @param string The input string to be checked for unique characters.
     * @return `true` if all characters in the string are unique, `false` otherwise.
     */
    fun hasUniqueCharactersBest(string: String) = string.length == string.toSet().size

    /**
     * Determines whether a given string has all unique characters.
     *
     * Time complexity: O(n), where n is the number of characters in the string.
     *
     * @param string The input string to be checked for unique characters.
     * @return `true` if all characters in the string are unique, `false` otherwise.
     */
    fun hasUniqueCharactersBetter(string: String): Boolean {
        //Assuming ASCII character set (8-bit)
        //The string can not have all unique characters if it's length is greater than 128
        if (string.length > 128) {
            return false
        }

        val charSet = BooleanArray(128)

        for (char in string) {
            val index = char.code
            if (charSet[index]) {
                return false
            }
            charSet[index] = true
        }

        return true // All char are unique.
    }

}

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

  public final boolean hasUniqueCharactersBest(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String string
       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: aload_1
      11: checkcast     #29                 // class java/lang/CharSequence
      14: invokestatic  #35                 // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      17: invokeinterface #40,  1           // InterfaceMethod java/util/Set.size:()I
      22: if_icmpne     29
      25: iconst_1
      26: goto          30
      29: iconst_0
      30: ireturn

  public final boolean hasUniqueCharactersBetter(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String string
       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: sipush        128
      13: if_icmple     18
      16: iconst_0
      17: ireturn
      18: sipush        128
      21: newarray       boolean
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_1
      27: invokevirtual #27                 // Method java/lang/String.length:()I
      30: istore        4
      32: iload_3
      33: iload         4
      35: if_icmpge     69
      38: aload_1
      39: iload_3
      40: invokevirtual #46                 // Method java/lang/String.charAt:(I)C
      43: istore        5
      45: iload         5
      47: istore        6
      49: aload_2
      50: iload         6
      52: baload
      53: ifeq          58
      56: iconst_0
      57: ireturn
      58: aload_2
      59: iload         6
      61: iconst_1
      62: bastore
      63: iinc          3, 1
      66: goto          32
      69: iconst_1
      70: ireturn
}

Compiled from "IsUnique.kt"
public final class ctci.arrays_and_strings._01_is_unique.IsUniqueKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String vishal
       2: astore_0
       3: ldc           #10                 // String sehgal
       5: astore_1
       6: ldc           #12                 // String linkedin
       8: astore_2
       9: ldc           #14                 // String google
      11: astore_3
      12: new           #16                 // class java/lang/StringBuilder
      15: dup
      16: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
      19: ldc           #21                 // String String:
      21: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      28: ldc           #27                 // String  has all unique characters:
      30: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      33: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
      36: dup
      37: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
      40: aload_0
      41: invokevirtual #34                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBetter:(Ljava/lang/String;)Z
      44: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
      47: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      50: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
      53: swap
      54: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      57: new           #16                 // class java/lang/StringBuilder
      60: dup
      61: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
      64: ldc           #21                 // String String:
      66: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      69: aload_1
      70: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      73: ldc           #27                 // String  has all unique characters:
      75: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      78: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
      81: dup
      82: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
      85: aload_1
      86: invokevirtual #34                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBetter:(Ljava/lang/String;)Z
      89: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
      92: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      95: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
      98: swap
      99: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     102: new           #16                 // class java/lang/StringBuilder
     105: dup
     106: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
     109: ldc           #21                 // String String:
     111: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     114: aload_2
     115: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     118: ldc           #27                 // String  has all unique characters:
     120: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     123: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
     126: dup
     127: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
     130: aload_2
     131: invokevirtual #34                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBetter:(Ljava/lang/String;)Z
     134: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     137: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     140: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     143: swap
     144: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     147: new           #16                 // class java/lang/StringBuilder
     150: dup
     151: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
     154: ldc           #21                 // String String:
     156: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     159: aload_3
     160: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     163: ldc           #27                 // String  has all unique characters:
     165: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     168: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
     171: dup
     172: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
     175: aload_3
     176: invokevirtual #34                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBetter:(Ljava/lang/String;)Z
     179: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     182: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     185: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     188: swap
     189: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     192: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     195: invokevirtual #55                 // Method java/io/PrintStream.println:()V
     198: new           #16                 // class java/lang/StringBuilder
     201: dup
     202: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
     205: ldc           #21                 // String String:
     207: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     210: aload_0
     211: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     214: ldc           #27                 // String  has all unique characters:
     216: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     219: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
     222: dup
     223: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
     226: aload_0
     227: invokevirtual #58                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBest:(Ljava/lang/String;)Z
     230: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     233: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     236: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     239: swap
     240: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     243: new           #16                 // class java/lang/StringBuilder
     246: dup
     247: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
     250: ldc           #21                 // String String:
     252: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     255: aload_1
     256: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     259: ldc           #27                 // String  has all unique characters:
     261: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     264: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
     267: dup
     268: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
     271: aload_1
     272: invokevirtual #58                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBest:(Ljava/lang/String;)Z
     275: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     278: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     281: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     284: swap
     285: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     288: new           #16                 // class java/lang/StringBuilder
     291: dup
     292: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
     295: ldc           #21                 // String String:
     297: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     300: aload_2
     301: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     304: ldc           #27                 // String  has all unique characters:
     306: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     309: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
     312: dup
     313: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
     316: aload_2
     317: invokevirtual #58                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBest:(Ljava/lang/String;)Z
     320: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     323: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     326: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     329: swap
     330: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     333: new           #16                 // class java/lang/StringBuilder
     336: dup
     337: invokespecial #19                 // Method java/lang/StringBuilder."<init>":()V
     340: ldc           #21                 // String String:
     342: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     345: aload_3
     346: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     349: ldc           #27                 // String  has all unique characters:
     351: invokevirtual #25                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     354: new           #29                 // class ctci/arrays_and_strings/_01_is_unique/IsUnique
     357: dup
     358: invokespecial #30                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique."<init>":()V
     361: aload_3
     362: invokevirtual #34                 // Method ctci/arrays_and_strings/_01_is_unique/IsUnique.hasUniqueCharactersBetter:(Ljava/lang/String;)Z
     365: invokevirtual #37                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
     368: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     371: getstatic     #47                 // Field java/lang/System.out:Ljava/io/PrintStream;
     374: swap
     375: invokevirtual #53                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     378: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #66                 // Method main:()V
       3: return
}


package codechef.snackdown2021.round1a

import kotlin.math.abs

private fun solve(): Int {
	readLn()
	val a = readInts().sorted()
	if (a.size == 2) return 0
	var ans = minOf(makeEqual(a.drop(1)), makeEqual(a.dropLast(1))).coerceInInt()
	var i = 1
	var j = a.lastIndex - 1
	val borders = a[0] + a.last()
	while (i < j) {
		ans = minOf(ans, abs(a[i] + a[j] - borders))
		if (a[i] + a[j] < borders) i++ else j--
	}
	return ans
}

private fun makeEqual(a: List<Int>): Long {
	val prefixSums = a.runningFold(0L, Long::plus)
	fun sum(from: Int, to: Int) = prefixSums[to] - prefixSums[from]
	return a.indices.minOf { a[it] * (2L * it - a.size) + sum(it, a.size) - sum(0, it) }
}

@Suppress("UNUSED_PARAMETER") // Kotlin 1.2
fun main(args: Array<String>) = repeat(readInt()) { println(solve()) }

private fun Long.coerceInInt() = if (this >= Int.MAX_VALUE) Int.MAX_VALUE else if (this <= Int.MIN_VALUE) Int.MIN_VALUE else toInt()

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "d.kt"
public final class codechef.snackdown2021.round1a.DKt {
  private static final int solve();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: pop
       4: invokestatic  #14                 // Method readInts:()Ljava/util/List;
       7: checkcast     #16                 // class java/lang/Iterable
      10: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      13: astore_0
      14: aload_0
      15: invokeinterface #27,  1           // InterfaceMethod java/util/List.size:()I
      20: iconst_2
      21: if_icmpne     26
      24: iconst_0
      25: ireturn
      26: aload_0
      27: checkcast     #16                 // class java/lang/Iterable
      30: iconst_1
      31: invokestatic  #31                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      34: invokestatic  #35                 // Method makeEqual:(Ljava/util/List;)J
      37: aload_0
      38: iconst_1
      39: invokestatic  #39                 // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
      42: invokestatic  #35                 // Method makeEqual:(Ljava/util/List;)J
      45: invokestatic  #45                 // Method java/lang/Math.min:(JJ)J
      48: invokestatic  #49                 // Method coerceInInt:(J)I
      51: istore_1
      52: iconst_1
      53: istore_2
      54: aload_0
      55: invokestatic  #53                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      58: iconst_1
      59: isub
      60: istore_3
      61: aload_0
      62: iconst_0
      63: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #59                 // class java/lang/Number
      71: invokevirtual #62                 // Method java/lang/Number.intValue:()I
      74: aload_0
      75: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      78: checkcast     #59                 // class java/lang/Number
      81: invokevirtual #62                 // Method java/lang/Number.intValue:()I
      84: iadd
      85: istore        4
      87: iload_2
      88: iload_3
      89: if_icmpge     174
      92: iload_1
      93: aload_0
      94: iload_2
      95: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     100: checkcast     #59                 // class java/lang/Number
     103: invokevirtual #62                 // Method java/lang/Number.intValue:()I
     106: aload_0
     107: iload_3
     108: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     113: checkcast     #59                 // class java/lang/Number
     116: invokevirtual #62                 // Method java/lang/Number.intValue:()I
     119: iadd
     120: iload         4
     122: isub
     123: invokestatic  #70                 // Method java/lang/Math.abs:(I)I
     126: invokestatic  #73                 // Method java/lang/Math.min:(II)I
     129: istore_1
     130: aload_0
     131: iload_2
     132: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     137: checkcast     #59                 // class java/lang/Number
     140: invokevirtual #62                 // Method java/lang/Number.intValue:()I
     143: aload_0
     144: iload_3
     145: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     150: checkcast     #59                 // class java/lang/Number
     153: invokevirtual #62                 // Method java/lang/Number.intValue:()I
     156: iadd
     157: iload         4
     159: if_icmpge     168
     162: iinc          2, 1
     165: goto          87
     168: iinc          3, -1
     171: goto          87
     174: iload_1
     175: ireturn

  private static final long makeEqual(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: checkcast     #16                 // class java/lang/Iterable
       4: astore_2
       5: lconst_0
       6: invokestatic  #87                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       9: astore_3
      10: iconst_0
      11: istore        4
      13: aload_2
      14: bipush        9
      16: invokestatic  #91                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: istore        6
      21: iload         6
      23: ifne          33
      26: aload_3
      27: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      30: goto          144
      33: new           #97                 // class java/util/ArrayList
      36: dup
      37: iload         6
      39: iconst_1
      40: iadd
      41: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
      44: astore        8
      46: aload         8
      48: astore        9
      50: iconst_0
      51: istore        10
      53: aload         9
      55: aload_3
      56: invokevirtual #105                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      59: pop
      60: aload         8
      62: astore        11
      64: aload_3
      65: astore        8
      67: aload_2
      68: invokeinterface #109,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      73: astore        9
      75: aload         9
      77: invokeinterface #115,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      82: ifeq          139
      85: aload         9
      87: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      92: astore        10
      94: aload         8
      96: aload         10
      98: checkcast     #59                 // class java/lang/Number
     101: invokevirtual #62                 // Method java/lang/Number.intValue:()I
     104: istore        12
     106: checkcast     #59                 // class java/lang/Number
     109: invokevirtual #123                // Method java/lang/Number.longValue:()J
     112: lstore        13
     114: iconst_0
     115: istore        15
     117: lload         13
     119: iload         12
     121: i2l
     122: ladd
     123: invokestatic  #87                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     126: astore        8
     128: aload         11
     130: aload         8
     132: invokevirtual #105                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     135: pop
     136: goto          75
     139: aload         11
     141: checkcast     #24                 // class java/util/List
     144: astore_1
     145: aload_0
     146: checkcast     #125                // class java/util/Collection
     149: invokestatic  #129                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
     152: checkcast     #16                 // class java/lang/Iterable
     155: invokeinterface #109,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore_3
     161: aload_3
     162: invokeinterface #115,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     167: ifne          178
     170: new           #131                // class java/util/NoSuchElementException
     173: dup
     174: invokespecial #134                // Method java/util/NoSuchElementException."<init>":()V
     177: athrow
     178: aload_3
     179: checkcast     #136                // class kotlin/collections/IntIterator
     182: invokevirtual #139                // Method kotlin/collections/IntIterator.nextInt:()I
     185: istore        4
     187: iconst_0
     188: istore        6
     190: aload_0
     191: iload         4
     193: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     198: checkcast     #59                 // class java/lang/Number
     201: invokevirtual #123                // Method java/lang/Number.longValue:()J
     204: ldc2_w        #140                // long 2l
     207: iload         4
     209: i2l
     210: lmul
     211: aload_0
     212: invokeinterface #27,  1           // InterfaceMethod java/util/List.size:()I
     217: i2l
     218: lsub
     219: lmul
     220: aload_1
     221: iload         4
     223: aload_0
     224: invokeinterface #27,  1           // InterfaceMethod java/util/List.size:()I
     229: invokestatic  #145                // Method makeEqual$sum:(Ljava/util/List;II)J
     232: ladd
     233: aload_1
     234: iconst_0
     235: iload         4
     237: invokestatic  #145                // Method makeEqual$sum:(Ljava/util/List;II)J
     240: lsub
     241: lstore        4
     243: aload_3
     244: invokeinterface #115,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     249: ifeq          332
     252: aload_3
     253: checkcast     #136                // class kotlin/collections/IntIterator
     256: invokevirtual #139                // Method kotlin/collections/IntIterator.nextInt:()I
     259: istore        6
     261: iconst_0
     262: istore        8
     264: aload_0
     265: iload         6
     267: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     272: checkcast     #59                 // class java/lang/Number
     275: invokevirtual #123                // Method java/lang/Number.longValue:()J
     278: ldc2_w        #140                // long 2l
     281: iload         6
     283: i2l
     284: lmul
     285: aload_0
     286: invokeinterface #27,  1           // InterfaceMethod java/util/List.size:()I
     291: i2l
     292: lsub
     293: lmul
     294: aload_1
     295: iload         6
     297: aload_0
     298: invokeinterface #27,  1           // InterfaceMethod java/util/List.size:()I
     303: invokestatic  #145                // Method makeEqual$sum:(Ljava/util/List;II)J
     306: ladd
     307: aload_1
     308: iconst_0
     309: iload         6
     311: invokestatic  #145                // Method makeEqual$sum:(Ljava/util/List;II)J
     314: lsub
     315: lstore        6
     317: lload         4
     319: lload         6
     321: lcmp
     322: ifle          243
     325: lload         6
     327: lstore        4
     329: goto          243
     332: lload         4
     334: lreturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #169                // String args
       3: invokestatic  #175                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: invokestatic  #178                // Method readInt:()I
       9: istore_1
      10: iconst_0
      11: istore_2
      12: iload_2
      13: iload_1
      14: if_icmpge     42
      17: iload_2
      18: istore_3
      19: iconst_0
      20: istore        4
      22: invokestatic  #180                // Method solve:()I
      25: istore        5
      27: getstatic     #186                // Field java/lang/System.out:Ljava/io/PrintStream;
      30: iload         5
      32: invokevirtual #191                // Method java/io/PrintStream.println:(I)V
      35: nop
      36: iinc          2, 1
      39: goto          12
      42: return

  private static final int coerceInInt(long);
    Code:
       0: lload_0
       1: ldc2_w        #194                // long 2147483647l
       4: lcmp
       5: iflt          13
       8: ldc           #196                // int 2147483647
      10: goto          28
      13: lload_0
      14: ldc2_w        #197                // long -2147483648l
      17: lcmp
      18: ifgt          26
      21: ldc           #199                // int -2147483648
      23: goto          28
      26: lload_0
      27: l2i
      28: ireturn

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #205                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #209                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: invokestatic  #215                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: checkcast     #219                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #221                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #223                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #229                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #232                // Method readStrings:()Ljava/util/List;
       3: checkcast     #16                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #97                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #91                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #125                // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #109,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #115,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #221                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #215                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #235                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #236,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #24                 // class java/util/List
      96: nop
      97: areturn

  private static final long makeEqual$sum(java.util.List<java.lang.Long>, int, int);
    Code:
       0: aload_0
       1: iload_2
       2: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #59                 // class java/lang/Number
      10: invokevirtual #123                // Method java/lang/Number.longValue:()J
      13: aload_0
      14: iload_1
      15: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      20: checkcast     #59                 // class java/lang/Number
      23: invokevirtual #123                // Method java/lang/Number.longValue:()J
      26: lsub
      27: lreturn
}