---
# System prepended metadata

title: Variable Length Subarray Puzzle Apporach

---

# Variable Length Subarray Puzzle Apporach
The problem is to output an array of size equal to that of input array. The elements of the output array should start with values beginning at `start` and ending at the `end-1` values of the input array and the rest of the values equal to 0.

Since, slicing is not available in circom we have to use a for loop to go through each value & decide whether it comes from the `input` array or is set to `0`.

We also do not have `if` in circom. So, we have to calculate all the branches of the logic and then use a multiplexer to choose the branch we want.

In the for loop we need to decide for each element if it is to be an elment from the input array or it needs to be set to `0`. This gives us `2` branches to calculate for each element. The first branch in our case is the value of `0` and the second branch is the value of the element between `start` & `end` based on where we are in the for loop. Based on where we are in the for loop we decide whether we go with the first branch or the second. If we are in for loop between `start` & `end` supplied inclusive of `start` & exclusive of `end`. We choose the value from the input array else we choose `0`.

To ensure that we are between `start` & `end` we have to add constraints. We keep a track of where we are in the loop with `count`. The `count` is initialized to start. We have to set one constraint to check that the `count` is less than end.