<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Heap on Dinçer Bakkal</title>
    <link>https://www.dincerbakkal.com/tags/heap/</link>
    <description>Recent content in Heap on Dinçer Bakkal</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-US</language>
    <copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright>
    <lastBuildDate>Mon, 02 Aug 2021 19:12:05 +0300</lastBuildDate><atom:link href="https://www.dincerbakkal.com/tags/heap/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Leetcode 767 Reorganize String</title>
      <link>https://www.dincerbakkal.com/posts/leetcode767/</link>
      <pubDate>Mon, 02 Aug 2021 19:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode767/</guid>
      <description>Return any possible rearrangement of s or return &amp;quot;&amp;quot; if not possible.
Input: s = &amp;quot;aab&amp;quot; Output: &amp;quot;aba&amp;quot; Input: s = &amp;quot;aaab&amp;quot; Output: &amp;quot;&amp;quot;  We use max heap to solve this question. We need to calculate the frequence of each letter. The we store the letter and frequence as pair based on its frequence in max heap and we pop the first letter and frequence pair from heap as the pre pair and append the letter to result string.</description>
    </item>
    
    <item>
      <title>Leetcode 215 Kth Largest Element in an Array</title>
      <link>https://www.dincerbakkal.com/posts/leetcode215/</link>
      <pubDate>Sun, 01 Aug 2021 19:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode215/</guid>
      <description>Note that it is the kth largest element in the sorted order, not the kth distinct element.
Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4  You can build a heap from input array and pop the heap until there k element left. Building heap is taking O(nlogn) time complexity.  def findKthLargest(self, nums: List[int], k: int) -&amp;gt; int: heapq.heapify(nums) amount = len(nums) while amount &amp;gt; k: heapq.</description>
    </item>
    
    <item>
      <title>Leetcode 451 Sort Characters By Frequency</title>
      <link>https://www.dincerbakkal.com/posts/leetcode451/</link>
      <pubDate>Thu, 29 Jul 2021 19:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode451/</guid>
      <description>Return the sorted string. If there are multiple answers, return any of them.
Input: s = &amp;quot;tree&amp;quot; Output: &amp;quot;eert&amp;quot; Explanation: &#39;e&#39; appears twice while &#39;r&#39; and &#39;t&#39; both appear once. So &#39;e&#39; must appear before both &#39;r&#39; and &#39;t&#39;. Therefore &amp;quot;eetr&amp;quot; is also a valid answer. Input: s = &amp;quot;cccaaa&amp;quot; Output: &amp;quot;aaaccc&amp;quot; Explanation: Both &#39;c&#39; and &#39;a&#39; appear three times, so both &amp;quot;cccaaa&amp;quot; and &amp;quot;aaaccc&amp;quot; are valid answers. Note that &amp;quot;cacaca&amp;quot; is incorrect, as the same characters must be together.</description>
    </item>
    
    <item>
      <title>Leetcode 347 Top K Frequent Elements</title>
      <link>https://www.dincerbakkal.com/posts/leetcode347/</link>
      <pubDate>Wed, 28 Jul 2021 19:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode347/</guid>
      <description>Soru Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
Örnek 1 Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Örnek 2 Input: nums = [1], k = 1 Output: [1] Çözüm  First we need count the appearence for each element store it in dictionary. Then we iterate the dictionary, and push the value-key pair (or count-value pair) into heap, if the the heap length less than k.</description>
    </item>
    
    <item>
      <title>Leetcode 973 K Closest Points to Origin</title>
      <link>https://www.dincerbakkal.com/posts/leetcode973/</link>
      <pubDate>Tue, 27 Jul 2021 19:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode973/</guid>
      <description>The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2).
You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).
 Input: points = [[1,3],[-2,2]], k = 1 Output: [[-2,2]] Explanation: The distance between (1, 3) and the origin is sqrt(10). The distance between (-2, 2) and the origin is sqrt(8).</description>
    </item>
    
    <item>
      <title>Leetcode 621 Task Scheduler</title>
      <link>https://www.dincerbakkal.com/posts/leetcode621/</link>
      <pubDate>Wed, 07 Jul 2021 19:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode621/</guid>
      <description>Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.
However, there is a non-negative integer n that represents the cooldown period between two same tasks (the same letter in the array), that is that there must be at least n units of time between any two same tasks.</description>
    </item>
    
    <item>
      <title>Leetcode 373 Find K Pairs with Smallest Sums</title>
      <link>https://www.dincerbakkal.com/posts/leetcode373/</link>
      <pubDate>Fri, 02 Jul 2021 19:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode373/</guid>
      <description>You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
Define a pair (u, v) which consists of one element from the first array and one element from the second array.
Return the k pairs (u1, v1), (u2, v2), &amp;hellip;, (uk, vk) with the smallest sums.
Input: nums1 = [1,7,11], nums2 = [2,4,6], k = 3 Output: [[1,2],[1,4],[1,6]] Explanation: The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6] Input: nums1 = [1,1,2], nums2 = [1,2,3], k = 2 Output: [[1,1],[1,1]] Explanation: The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3] and let&amp;rsquo;s say k=3</description>
    </item>
    
    <item>
      <title>Leetcode 378 Kth Smallest Element in a Sorted Matrix</title>
      <link>https://www.dincerbakkal.com/posts/leetcode378/</link>
      <pubDate>Fri, 21 May 2021 20:12:05 +0300</pubDate>
      
      <guid>https://www.dincerbakkal.com/posts/leetcode378/</guid>
      <description>Given an n x n matrix where each of the rows and columns are sorted in ascending order, return the kth smallest element in the matrix.
Note that it is the kth smallest element in the sorted order, not the kth distinct element.
Input: matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8 Output: 13 Explanation: The elements in the matrix are [1,5,9,10,11,12,13,13,15], and the 8th smallest number is 13 Input: matrix = [[-5]], k = 1 Output: -5   Use Heap to solve the question.</description>
    </item>
    
  </channel>
</rss>
