a blog about nothing

Leetcode 92: Reverse Linked List II


Here is my leetcode solution in JavaScript:

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} left
 * @param {number} right
 * @return {ListNode}
 */
var reverseBetween = function(head, left, right) {
    let currPos = 1;
    let currNode = head;
    let startNode = head;
    let endNode = null;

    while(currPos < left) {
        startNode = currNode;
        currNode = currNode.next;
        currPos++;
    }

    let newList = null;
    let tail = currNode;

    while (currPos <= right) {
        const next = currNode.next;
        currNode.next = newList;
        newList = currNode;
        currNode = next;
        currPos++;
    }

    startNode.next = newList;
    tail.next = currNode;

    if (left > 1) {
        return head;
    }

    return newList;


};

Link to problem.

Read more ⟶

Ayden & Simba go to the Moon


Ayden and Simba were playing when they saw the moon. Ayden wanted to go to moon but didn’t know how. Then Simba remembered their friend Rocky the Red Rocket can take them to the moon. They went to Rocky’s house but he was not there. Simba said let me find him because he can find anyone by sniffing their smells. Simba sniffed and sniffed and found Rocky swimming in the pool. Once upon a time, there was a little boy named Ayden and he had a little dog called Simba. One day Aydne said to Simba, he lute’s go to moon. Since said that is an excellent idea. So Ayden and Simba went to their friend, Rock the red rocket’s house. They knocked on the door but no one answered. Simba sniffed and sniff and found Rocky at the pool. “Hey Rocky, how are you?’ asked Ayden. “I am good fellas, what are you guys up to” replied Rocky “We really really want to go to the moon, when you go to moon next time, can you please take us with you?” Ayden asked politely. Rocky said, oh guess what, I am going to moon right now. Let’s go now, if you can.” Simba nd Ayden got excited and they jumped in the Rocky. 3, 2, 1, Blast off!!! Rocky went into space and then landed on the moon. Moon was so beautiful, Ayden and Simba got out and started to play on the moon. It was very bouncy and it was red. And it smelled like a cheese. So Simba licked the moon’s surface and said moon tastes like cheese too. Ayden took a small bite of moon and guess what, moon is indeed made out of cheese. Simba and Ayden ate a lot of moon. They got so full. Rocky called them and said it is time to go back home. Rocky took them back home and Ayden and Simba thanked Rocky. And then took a nice big nap!

Read more ⟶

Blue Bus and Yummy Apples


One day, Blue Bus wanted to eat yummy yummy apples. He looked in the fridge but there were no of apples. He went to Target to buy apples. But Target was out of apples too. Then Blue Bus went to Red Bus but Red Bus was out of apples too. She had just eaten the last apple Blue Bus then went to Green Bus’s home. Green Bus was out of apples too. Blue Bus then went to Yellow Bus. Yellow Bus had just got back home from his work. Blue Bus asked if he had any apples but Yellow Bus was out of apples too. But Yellow Bus had just dropped Ayden at his home and Ayden had a big bag of apples. Blue Bus finally went to Ayden’s home. He asked if Ayden had any apples. Ayden said, “yes I do, right here in my pockets”. Then Ayden gave one apple to Blue Bus. Then all the buses came, Ayden shared his apples with everyone and they all ate apples together.

Read more ⟶

Broken Dreams/Bheegi Yadein by Junoon


As I turn back, my eyes dampen

When I realized my incomplete life

My life became clear to me

Broken promises

Deserted dreams

Broken promises

Seek time's tender shade

Yesterday too, was in ruins

Now is deserted as well

Life asks for a moment of support

Damp memories

Won't let me sleep due to grief

Damp memories

Won't let me live.

By Junoon

Read more ⟶

Yellow Bus and Red Car


Once upon a time there was a Yellow bus. Yellow bus was very fast, but there was a Red car which was faster. One day, Red car challenged yellow bus for a race. They decided to race from Dallas to Houston. It was the longest race ever. All the cars gathered around the highway. Referee said 1, 2, 3, Go! Yellow bus goes zoom zoom. But red car goes zoom zoom zooooom. And Red car was faster and it was winning. After a while Red car looked in its rearview mirror and didn’t see Yellow bus at all. Red car’s engine was overheating, and it was running low on gas. Up ahead was a gas station. Red car decided to pull into gas station to refill gas and and cool down the engine in a shade. While resting in the shade, it fell asleep. Yellow bus, however, didn’t stop. It kept going and going until it crossed the finish line. Red car woke up and realized, it slept for too long. It raced to finish line but Yellow bus had already won the race. Red car was surprised and asked how did you not take a break, Yellow bus said by going fast but not too fast. They laughed and then went to eat ice cream. Moral of story, go fast but not too fast.

Read more ⟶

A Poem by Mirza Ghalib


Mirza Ghalib was the one of the greatest Urdu poet from 19th century. I translated this poem for a school project.

I look at the joys of this world, as I look at the dust.



Crying used to give me pleasure but now my eyes have gone dry.



When I am dead, wind might take my dust to my destination.



Because now I have no more strength to continue.



For whom are these preparations of welcome, who is this lover from the heaven?



All I see is flowers, and nothing else.



My love has left me capable of nothing.



Now I just wish to live quietly somewhere.



Asad, my poetry is for times past.



It is useless to write, when no one understands.<br />
Read more ⟶

I


Who is that is I



Still lost in my mind.



Trying to find my purpose,



When there might not be one.



The first thing was writing



Can words truly change anything?



Why should I write,



When there is so much noise



Are you in that house,



Or are you out here.



I will give up now,



This desert is just too vast.



My voice will not reach you,



Is this even a language.



What is music when there is no rhythm.



Why should I write,



When I have nothing to say.

Wrote this poem long time ago, it seems it is still applicable.

Read more ⟶

A poem by Mir Taqi Mir


Stop crying, this is just the beginning of love.



Hold on and see what will be next.



In the morning, there were voices in the caravan.



Let's move on and let the sleeper sleep.



On this ground nothing can grow.



Please stop planting seeds of hopes in your heart.



These are marks of true love, they remain forever.



It is not possible to wash them away from your heart.



Time was more important than anything else in my life.



And Mir, I wasted my time foolishly.<br />

This was another college project, I translated this poem by Mir Taqi Mir.

Read more ⟶

A Poem by Mir Dard


It was a school or temple, or was it Makkah or a church.
We were all guests, only you were the host.



Oh! How sad it is. I found just before death.
It was only a dream, what I saw. It was only a fairy tale, what I heard.



How sad it is that autumn is in the garden.
There was some grass, which was my friend.



This place is getting chaotic with all these people coming and going.
My heart used to be the place for your peace.



It is useless to remember them, try to be happy.
Dard, it is not important if they remember me or not.<br />

Mir Dard was a sufi poet from India. I translated this poem for college project.

Read more ⟶

A poem by Allama Iqbal


You are neither for earth nor for the heavens.

The world is for you; you are not for the world.

This garden is the place for pain and prayer.

Not for picking flowers or building a nest.

How long will you stay in the rivers of Ravi, Nile, and Farat?

Your ship was built for infinite oceans.

It was nothing, what we have exaggerated.

We made it more, just for our fantasies.

Read more ⟶