Tags » Linked List

Problem of the day: Detecting cycle in a linked list

Today I was looking at problems related to linked lists. They tend to be asked quite a lot in interviews but some of them look artificial with their complexity arising from linked lists being a poor data structure for the problem (e.g., median of a sorted linked list). 705 more words


Reverse a Linked List

This is a soooo….ooo frequently asked interview question which I can’t even emphasize more! However the steps towards this question is easily forgotten by a lot of programmers. 248 more words

Data Structure

Summary of reverse linked list

method 1

class Solution {
    ListNode* reverseList(ListNode* head) {
        ListNode* new_head = new ListNode(0);
        new_head -> next = head;
        ListNode* pre = new_head;
        ListNode* cur = head; 
        while (cur && cur -> next) {
            ListNode* temp = pre -> next;
            pre -> next = cur -> next;
            cur -> next = cur -> next -> next; 
            pre -> next -> next = temp;
        return new_head -> next;
… 71 more words
Data Structure

Design Phone Directory


Design a Phone Directory which supports the following operations:

  1. get: Provide a number which is not assigned to anyone.
  2. check: Check if a number is available or not.
  3. 360 more words
Algo & Code (leetcode / C++)