Sanjay Gatti’s Post

SQL Challenge 9/100 : Best Time to Trade Stock 📈 (Part-4) 💪 Difficulty - Hard 🔗 Part 3: Refer old post You are given a table with stock prices 📊 🎯 Problem Let’s make it tougher 👇 👉 You can make at most 2 transactions 🔁 👉 You cannot hold multiple stocks at the same time 🚫📦 👉 Must sell before buying again 🔄 ❓ Your Task Write a SQL query to: ✅ Return maximum profit 💰 ✅ Also return the buy & sell days for both transactions\ ⚠️ Rules: Max 2 transactions only 🔢 No overlapping 🚫 Buy < Sell always ⏳ No hardcoding ❌ -- Create table CREATE TABLE stock_prices (   day INT,   price INT ); -- Insert data INSERT INTO stock_prices (day, price) VALUES (1, 100), (2, 180), (3, 260), (4, 310), (5, 40), (6, 535), (7, 695); Tagging Ankit Bansal Sumit Mittal for better reach Sanjay Gatti #SQL #DataEngineering #SQLChallenge #Analytics #LearnSQL 🚀

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories