diff --git a/submissions/Vaishnavi_Mishra/Question1/Screenshot(114).png b/submissions/Vaishnavi_Mishra/Question1/Screenshot(114).png new file mode 100644 index 0000000..0314f8f Binary files /dev/null and b/submissions/Vaishnavi_Mishra/Question1/Screenshot(114).png differ diff --git a/submissions/Vaishnavi_Mishra/Question1/solution.cpp b/submissions/Vaishnavi_Mishra/Question1/solution.cpp new file mode 100644 index 0000000..d410893 --- /dev/null +++ b/submissions/Vaishnavi_Mishra/Question1/solution.cpp @@ -0,0 +1,37 @@ +/*Problem 402: Remove K Digits +*Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num. +*/ + +#include +#include +using namespace std; + +class Solution { + public: + string removeKdigits(string num, int k) { + if (num.length() == k) + return "0"; + + string ans; + vector stack; + + for (int i = 0; i < num.length(); ++i) { + while (k > 0 && !stack.empty() && stack.back() > num[i]) { + stack.pop_back(); + --k; + } + stack.push_back(num[i]); + } + + while (k-- > 0) + stack.pop_back(); + + for (const char c : stack) { + if (c == '0' && ans.empty()) + continue; + ans += c; + } + + return ans.empty() ? "0" : ans; + } +}; \ No newline at end of file diff --git a/submissions/Vaishnavi_Mishra/Question2/Screenshot(115).png b/submissions/Vaishnavi_Mishra/Question2/Screenshot(115).png new file mode 100644 index 0000000..029e211 Binary files /dev/null and b/submissions/Vaishnavi_Mishra/Question2/Screenshot(115).png differ diff --git a/submissions/Vaishnavi_Mishra/Question2/solution.cpp b/submissions/Vaishnavi_Mishra/Question2/solution.cpp new file mode 100644 index 0000000..d1356e2 --- /dev/null +++ b/submissions/Vaishnavi_Mishra/Question2/solution.cpp @@ -0,0 +1,21 @@ +/*Problem 901: Online Stock Span +*Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day. +*The span of the stock's price in one day is the maximum number of consecutive days (starting from that day and going backward) for which the stock price was less than or equal to the price of that day. +*/ + +#include +using namespace std; + +class StockSpanner { + public: + int next(int price) { + int span = 1; + while (!stack.empty() && stack.top().first <= price) + span += stack.top().second, stack.pop(); + stack.emplace(price, span); + return span; + } + + private: + stack> stack; // (price, span) +}; \ No newline at end of file