AAshirinashirmehmood.hashnode.dev·Jun 17, 2024 · 1 min readFind Max In Rotated Sorted Array (medium)class Solution { public: int findMin(vector<int>& nums) { int n = nums.size() - 1; if (nums[0] <= nums[n]) { return nums[0]; } int l = 0, r = n, m = 0; while(l <= r) { ...00
AAshirinashirmehmood.hashnode.dev·Jun 12, 2024 · 1 min readCount of Positive and Negative Integers# written by Ashir O(logn) class Solution: def maximumCount(self, nums: List[int]) -> int: l, r = 0, len(nums) - 1 count_pos = 0 count_neg = 0 zeros = 0 if nums[0] == 0 and nums[-1] == 0: retu...00
AAshirinashirmehmood.hashnode.dev·Jun 7, 2024 · 1 min readFind Minimum in Rotated Sorted Array# written by Ashir class Solution: def findMin(self, nums: List[int]) -> int: m = nums[0] mid = 0 if len(nums) == 1: return nums[0] for i in range(len(nums) - 1): if nums[i + 1] < nums[i]: ...00
AAshirinashirmehmood.hashnode.dev·Jun 4, 2024 · 1 min readSearch In 2D Array// Written by Ashir class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { return search(matrix, target); } bool search(vector<vector<int>>& matrix, int& t) { if(matrix.size() == 0) ...00
AAshirinashirmehmood.hashnode.dev·May 26, 2024 · 1 min read1475. Final Prices With a Special Discount in a Shop (Easy)// next smaller number - monotonic stack class Solution { public: vector<int> finalPrices(vector<int>& prices) { int n = prices.size(); std::vector<int> ans(n); std::stack<int> s; for(int i = 0; i < prices.size(); i++) { ...00