
Today I solved the problem of sorting colors, or, to say, sorting an array of zeros, ones, and twos. This problem involved an array containing only zeros, ones, and twos, and we had to sort it so that the same kind of number was adjacent to each other. Okay,
- Brute force approach
In this approach, I thought of iterating through the array once to count the number of zeros, ones, and twos. Then we'll iterate through the array and place these numbers, along with their counts, adjacent to each other so that, in the end, we get a new array in which all the numbers are arranged in non-decreasing order.
- The better approach
In this approach, I thought, let's not do that, and let's not just iterate through the array once again and place the elements just there. What we can do is make it simpler and put 3 counters to count the zeros, ones, and twos. When we get this number, we can change the same array and iterate through it and place it at its respective positions. What it will do is we do not need to create a new array, and the space complexity will be lower.
- The most optimal approach
Was to use the Dutch national flag algorithm. In this algorithm, what we needed to do is we had to initialize 3 pointers:
- low, which is pointing to the low
- mid, which is initialized with 0, but it will point to the middle element of the array
- high, which is pointing to the last element of the array, n - 1 Ok, ay n is the size of the array. Here, what we needed to do is, if we encounter the middle element or the element at the middle index, if it is zero, then we can swap this element with the lowest element, like the element at the low index. Similarly, when we swap this, then we increment the index of low as well as mid. If we encounter one at the middle index or the mid index, then we do not do anything and just increment the count of middle because that is where it should be. If it is one, then it should be in the middle, and if we encounter the middle element or the element at the high index, then we will swap it with the element at the high index. When we swap the mid element or the element at the mid with the element at the high index, then we will decrement, or we will decrease the value of the high index, so that we can come to the values which are left in the array. We will not increment the mid index because after swapping the mid element, there must be zero or two, so we will not increment the count because this also needs processing. That's why we will not implement it. At the end, we will get the same array but sorted, and we won't need to create a new array. We will not have to iterate again and again, and the time complexity will be O(n). It will be the same for every approach that I shared, but for this, the space complexity will be much lower than the others.

Hey guys currently I am working on a road map type website like where you can enroll in a road map and continue thriving and learning and these all are personalised road map even you can add task or topics which you want in that road map and it will be customised for you. Some roadmaps have 2 to 3 task per day some have one task and some road maps are combined like suppose there is one of 90 days containing system design, DSA, devops and also CS fundamentals. Keep supporting guys I will share the link when I am done with the deployment and else.

Sometimes, I want to be written, instead of being a writer, I want to be a poem, instead of being a poet, I want to be chased upon,insted of chasing someone. I want to be happy, instead of making others happy. I want to be appreciated instead of appraising. and at the very last, I want to be loved,instead of loving.

Currently working on a project related to multi-agent system, upon completion it will provide a platform where users can connect different AI models and make different agents in the platform by entering different system prompts for different agents, also they can add local models through ollama or LMStudio and can use them as agents for specified task. After defining the agents users can then make workflows to show how the user input is going to be treated and executed to give preferred output. I haven't attached a readme file but the u can see the file structure here - NeuroMesh

My portfolio website link is thisisvivek