Leetcode Contest Problems

Photo by Emre on Unsplash

Leetcode Contest Problems

ยท

1 min read

Leetcode Weekly Contest 387

3069. Distribute Elements Into Two Arrays I

3070. Count Submatrices with Top-Left Element and Sum Less Than k

This is a dynamic programming problem

3071.Minimum Operations to write `Y` on grid

We can clearly see via the constraints that is is a backtracking problem

3072. Distribute Elements Into Two Arrays II

The problem is a application problem of lower and upper bound :

Notes

  1. For set iterators arithmetic operations dont work like they do for array iterators ex. the operator - is not defined for the iterators of std::sets (bidirectional iterators) while it's defined for the arrays iterators (random access iterators).

    Instead, you can use std::distance(), as follows

     int main()
     {
         set<int> set {1, 2, 4, 5, 6};
         int number = 3;
         int lbIdx=distance(set.begin(), set.lower_bound(number)) ;
         cout<<"lower bound Index"<< lbIdx <<endl;
     }
    
ย