Minimum Cost of ropes | Queue | Heap | GFG POTD | Dry Run & Explanation

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ต.ค. 2024
  • Guyz If you Like the Content
    Plz Consider:
    -Subscribing the Channel
    -Like the video
    -Comment your review
    #gfgpotd
    #leetcodepotd
    #algorithm
    #graph
    #datastructure
    #topologicalsort
    #directedgraph
    #graphalgorithm
    #sortalgorithm
    #dfs
    #kahnalgorithm
    #programming
    #coding
    #competitiveprogramming
    #codinginterview
    #interviewprep
    #graphtraversal
    #cp
    #dsa
    #GraphAlgorithms
    #GraphTheory
    #Algorithms
    #GFGPOTD (GeeksForGeeks Problem of the Day)
    #LeetCodePOTD (LeetCode Problem of the Day)
    #CompetitiveProgramming
    #DataStructures
    #SortingAlgorithms
    #DFS (Depth First Search)
    #KahnsAlgorithm
    #CodingChallenge
    #Programming
    #InterviewPrep
    #techinterview#education
    #MinimumCostOfRopes
    #RopeProblem
    #GFGPOTD
    #GeeksForGeeks
    #CodingChallenge
    #DailyCodingProblem
    #DataStructures
    #GreedyAlgorithm
    #ProgrammingTutorial
    #CodeWithMe
    #LearnToCode
    #InterviewPreparation
    #JavaScriptCoding
    #AlgorithmPractice
    #CompetitiveProgramming

ความคิดเห็น • 1

  • @Veom03
    @Veom03  28 วันที่ผ่านมา +1

    If You Like the Video then Plzz Consider Subscribing ☺.
    CODE-
    class Solution {
    public:
    long long minCost(vector& arr) {
    priority_queue pq;
    for(int i=0;i 1){
    long long first = pq.top();
    pq.pop();
    long long second = pq.top();
    pq.pop();
    sum += first+second;
    pq.push(first+second);
    }
    return sum;
    }
    };