en
Feedback
C++ Codes - Basic to Advanced 💻

C++ Codes - Basic to Advanced 💻

Open in Telegram

💡 Daily C++ Codes with Output & Logic Any queries, message 👉 @sai7981 🤖 Get instant code explanations: @cpp_codes_bot 🔗 Join now: @cpp_code_snippets #cpp #dsa #coding #programming

Show more
3 188
Subscribers
No data24 hours
+357 days
+12030 days
Posts Archive
https://amzn-to.co/bKmSzV GRAB IT AT 12PM Note - Only for First 50 Users
https://amzn-to.co/bKmSzV GRAB IT AT 12PM Note - Only for First 50 Users

🔥🔥OnePlus Nord 4 5G (Mercurial Silver, 8GB RAM, 256GB Storage) 🎁 Deal Price : ₹24,998 Buy Here : https://amzn-to.co/oX916u
🔥🔥OnePlus Nord 4 5G (Mercurial Silver, 8GB RAM, 256GB Storage) 🎁 Deal Price : ₹24,998 Buy Here : https://amzn-to.co/oX916u 💥 Bank Offer : ₹4,500 Off On AXIS & ICICI Credit Cards/EMI Txn

Samsung 653 L, 3 Star, Side By Side AI Enabled Smart Refrigerator ✔️Offer Price: ₹57,490 ❌Regular Price: ₹79,990 🔗Buy here:
Samsung 653 L, 3 Star, Side By Side AI Enabled Smart Refrigerator ✔️Offer Price: ₹57,490 ❌Regular Price: ₹79,990 🔗Buy here: https://amzn-to.co/aZ3LQV ➡️Apply ₹3000 coupon ➡️19,500 Off With HDFC CC

🔥🔥Pigeon 2 Slice Auto Pop up Toaster @699 Buy Here : https://amzn-to.co/EFJxgN
🔥🔥Pigeon 2 Slice Auto Pop up Toaster @699 Buy Here : https://amzn-to.co/EFJxgN

🔥🔥Dysen Office Chair. @3796 Buy Here : https://amzn-to.co/kZ5Z77 💥Apply 200 Coupon
🔥🔥Dysen Office Chair. @3796 Buy Here : https://amzn-to.co/kZ5Z77 💥Apply 200 Coupon

🔥🔥🔥Myntra Loot : Upto 85% Off On HRX Clothing. Men : https://myntr.in/2WRZ3y Low To High : https://myntr.in/pemzU2 Trackpa
🔥🔥🔥Myntra Loot : Upto 85% Off On HRX Clothing. Men : https://myntr.in/2WRZ3y Low To High : https://myntr.in/pemzU2 Trackpants : https://myntr.in/lawgcs Tracksuits : https://myntr.in/sVDoqM Women : https://myntr.in/VligWC Low To High : https://myntr.in/I4cWBP Trackpants  : https://myntr.in/C5eHba Tracksuits : https://myntr.in/7Ppom8

🔥🔥ThriveCo Water-based Sunscreen | Broad Spectrum & Spf 50 Pa++++ | UV A & UV B Protection @149 Buy Here : https://amzn-to.
🔥🔥ThriveCo Water-based Sunscreen | Broad Spectrum & Spf 50 Pa++++ | UV A & UV B Protection  @149 Buy Here : https://amzn-to.co/bQrYGY

IFB 8 Kg 5 Star Fully Automatic Front Load Washing Machine ✔️Offer Price: ₹27,990 ❌Regular Price: ₹33,490 🔗Buy here: https:/
IFB 8 Kg 5 Star Fully Automatic Front Load Washing Machine ✔️Offer Price: ₹27,990 ❌Regular Price: ₹33,490 🔗Buy here: https://amzn-to.co/pE7xKv ➡️Apply ₹1500 coupon ➡️4000 Off With HDFC CC

// Given a 2D array mXn in which,
// => Integer in each row is sorted from left to right
// => First integer of each row > last integer of previous row
//Output: if element present - return true
//        if element absent - return false
function binarySearchof2DArr(arr,m,n,value){
    let left=0;
    let right=(m*n)-1;
    while(left<=right){
        let mid=left+Math.floor((right-left)/2);
        let mid_element=arr[Math.floor(mid/n)][mid%n];
        if(mid_element === value){
            return true;
        }
        else if(mid_element < value){
            left=mid+1;
        }
        else{
            right=mid-1;
        }
    }
    return false;
}


let arr=[ [1,2,4,6], [10,11,16,20], [23,30,34,60] ];
let m=arr.length;
let n=arr[0].length;
let value=6;
let res=binarySearchof2DArr(arr,m,n,value);
console.log(res);

// time complexity - O(log(m*n))

// Best time for buying and selling the stocks 
function findMaxProfit(prices){
    let minValue=Number.MAX_SAFE_INTEGER;
    let maxValue=0;
    for(let i=0;i<prices.length;i++){
        if(prices[i]<minValue){
            minValue=prices[i];
        }
        else if(prices[i]-minValue > maxValue){
            maxValue=prices[i]-minValue;
        }
    }
    return maxValue;
}


// Driver code 
let prices=[7,1,4,6,5];
let maxProfit=findMaxProfit(prices);
console.log(maxProfit);

//time complexity: O(n)

// Two Pointer Approach
// Given an array [20,40,60,80,90,120,240] give the index of two numbers 
// for which sum will be 210.
function findIndex(arr,sum_val){
    let l=0;
    let r=arr.length-1;
    while(l<=r){
        if( (arr[l]+arr[r]) === sum_val){
            return [l,r];
        }
        else if(arr[l]+arr[r]>sum_val){
            r=r-1;
        }
        else{
            l=l+1;
        }
    }
}

let arr=[20,40,60,80,90,120,240];
let sum_val=210;
let [a,b]=findIndex(arr,sum_val);
console.log(`${arr[a]}+${arr[b]}=${arr[a]+arr[b]}`);

// time complexity: O(n)

// Binary Search 
// recursive approach 
function binarySearch(arr,x,left,right){
    let mid=left+Math.floor((right-left)/2);
    if(left>right){
        return -1;
    }
    else{
        if(arr[mid]===x){
            return mid;
        }
        else if(arr[mid] < x){
            return binarySearch(arr,x,mid+1,right);
        }
        else{
            return binarySearch(arr,x,left,mid-1);
        }
    }
}

let arr=[10,20,30,40,50];   //sorted array
let x=33;
let left=0;
let right=arr.length-1;
let res=binarySearch(arr,x,left,right);
if(res!=-1){
    console.log("Element found at ",res," index");
}
else{
    console.log("Element not found");
}

// time-complexity : O(log n)
// space-complexity : O(1)

// Binary Search 
// iterative approach 
function binarySearch(arr,x){
    let left=0;
    let right=arr.length-1;
    while(left<=right){
    let mid=left+Math.floor((right-left)/2);
        if(arr[mid] === x){
            return mid;
        }
        else if(arr[mid]<x){
            left=mid+1;
        }
        else{
            right=mid-1;
        }
    }
    return -1;
}

let arr=[10,20,30,40,50];   //sorted array
let x=50;
let res=binarySearch(arr,x);
if(res!=-1){
    console.log("Element found at ",res," index");
}
else{
    console.log("Element not found");
}

// time-complexity : O(log n)
// space-complexity : O(1)

// Linear Search 

function linearSearch(arr,x){
    for(let i=0;i<arr.length;i++){
        if(arr[i]==x){
            return i;
        }
    }
    return -1;
}
let arr=[10,34,21,54,77,53];
let x=77;
let res=linearSearch(arr,x);
if(res!=-1){
    console.log("Element found at ",res," position");
}
else{
    console.log("Element not found");
}

// time complexity- O(n)

// space complexity - O(1)

Array Data Structure:

Hey Everyone👋, Hope all are doing well, After researching a lot about which course to suggest for my channel members i have come across with this course, Tech Neuron by iNeuron. You can get many courses in this bundle(including dsa courses) ,which will help you entire your engineering, these courses are perfectly structured enough to give much skill to the students which companies expect. Once checkout the courses and watch the intros of the courses to ensure the quality of the content that you will get through these courses,the cost for these courses is really affordable. You can get a 10% discount by enrolling through below link👇 https://ineuron.ai/one-neuron/tech-neuron?campaign=affiliate&coupon_code=UENIHGZD Enroll and Enjoy learning👍

https://t.me/student_deals_loots Ajio Sale is live join for best dealz ☝️

https://t.me/java_programming_language_code join our java channel ☝️ Along with Leetcode questions solved will be uploaded