Guest User

Sliding Window Template

a guest
Jan 4th, 2025
3,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. [[nodiscard]] auto slidingWindow(const std::vector<int>& vec, /* */) -> /* */{
  2.   std::size_t l = 0;
  3.  
  4.   const auto addIndex = [&](std::size_t index){
  5.     // TODO: expand bound
  6.   };
  7.  
  8.   const auto removeIndex = [&](std::size_t index){
  9.     // TODO: shrink bound
  10.   };
  11.  
  12.   const auto updateBound = [&](std::size_t r){
  13.     addIndex(r);
  14.  
  15.     while(/* TODO: condition that make bound invalid */){
  16.       removeIndex(l);
  17.       l++;
  18.     }
  19.   };
  20.  
  21.   for(std::size_t r = 0; r < vec.size(); r++){
  22.     updateBound(r);
  23.     // TODO: do things with your bounds
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment