LeetCode Entry

1287. Element Appearing More Than 25% In Sorted Array

11.12.2023 easy 2023 kotlin

Most frequent element

1287. Element Appearing More Than 25% In Sorted Array easy blog post substack image.png

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/435

Problem TLDR

Most frequent element

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(n)\), can be O(1)

Code


  fun findSpecialInteger(arr: IntArray): Int =
    arr.groupBy { it }
      .maxBy { (k, v) -> v.size }!!
      .key