Update appNew update is available. Click here to update.
About
JIS College of engineering 2020
My Stats
EXP gained
yellow-spark
6671
Level
6 (Specialist)
Community stats
Discussions
2
Upvotes
2
Know more
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
94
Total problems solved
41
Easy
45
Moderate
8
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

1 day

Longest streak:

4 days

Less

More

Achievements
1
Ronin
Topics
Linked List
2
Samurai
Topics
Arrays
+ 1 more
Discussions
Simple Java Solution || T.C : O(1)
Interview problems

Node front = new Node(-1);

    Node curr = front;

    Node rear = null;

    public void push(int x) {

        // Write Your Code Here

        // Here create a dummy node at the first and start adding nodes to the linked list when push operation is called. 

        //Since queue follows FIFO principle, during pop operation try deleting nodes from the head/front of linked list.

        //Now if during midway, the linkedlist becomes empty, create the dummy node again and start attaching nodes again at the end.

        if(front==null){

            front = new Node(-1);

            curr = front;

        }

        rear = new Node(x);

        curr.next = rear;

        curr = rear;

    }

 

    public int pop() {

        // Write Your Code Here

        if(front == null || (front.data == -1 && front.next == null)) return -1;

        

        if(front.data==-1){

            front = front.next;

        }

        

        Node node = front.next;

        front.next = null;

        int data = front.data;

        front = node;

 

        return data;

    }

profile
saswata mukherjee
Published On 06-Dec-2023
17 views
0 replies
0 upvotes
JAVA Code which passes all test cases
Interview problems

int[] dist = new int[n+1];

        for(int i=1;i<=n;i++){

            dist[i] = (int) (1e8);

        }

 

        dist[src]=0;

 

        // Iterating through (V-1) times

        for(int i=1;i<=n-1;i++){

            for(List<Integer> edge : edges){

                int u = edge.get(0);

                int v = edge.get(1);

                int wt = edge.get(2);

 

                if(dist[u] + wt < dist[v]){

                    dist[v] = dist[u] + wt;

                }

            }

        }

profile
saswata mukherjee
Published On 15-Nov-2023
47 views
0 replies
0 upvotes