resources
go gobyexample.com (10/10) packagces cobra cobra primer by redhat people ⇒ opdev.github.io/cobra-primer/ slog www.dash0.com/guides/logging-in-go-with-slog.
go gobyexample.com (10/10) packagces cobra cobra primer by redhat people ⇒ opdev.github.io/cobra-primer/ slog www.dash0.com/guides/logging-in-go-with-slog.
variadics rem: …type is the arg and for usage type is equivalent to []type func sum(nums ...int) int { total := 0 for _, num := range nums { total += num } return total } for calling sum(1,2,3) sum(nums...) where nums is []int note that the it’s …int and then nums… ⇒ the dirs are not the same.
a variation of 2119 that i use MUST / MUST NOT ⇒ absolutes SHOULD / SHOULD NOT ⇒ strongly recommended PREFER / AVOID ⇒ recommended ASSUME ⇒ invariant MAY / CAN ⇒ OPTIONAL added variations.
Design Patterns Creational Patterns How to create objects Factory Pattern When? Tight coupling between the client code and the concreate classes of a particular type.
Decrease subarray by 1, min operations to make it 0 Link: leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array int minNumberOperations(vector<int>& arr) { // rephrase // invert the problem, in one operation, can dec subarray by 1, convert to 0 // greedy, s...
Minimum range to sort to get a fully sorted array in O(n) and O(1) Link: leetcode.com/problems/shortest-unsorted-continuous-subarray/ Note that you can also use the “boundaries” approach here.
Cartesian Trees It’s just a binary tree where each node is greater/smaller (based on value or some derived priority) than all nodes in its left subtree and right subtree.
Count Subarrays with Fixed Bounds Quite an elegant solution once you realise the observation.
Subarray sums Max/min sum subarray ( trivial ) int maxSubArray(vector<int>& nums) { int curs = nums[0], mx = nums[0]; for (int i = 1; i < (int)nums.size(); i++) { curs = max(nums[i], curs + nums[i]); mx = max(curs, mx); } return mx; } Max/min sum circular subarray ( complement of min tr...