Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

Longest Common Prefix in an Array || Remove duplicate element from sorted Linked List

Longest Common Prefix in an Array :- Given an array of N strings, find the longest common prefix among all strings present in the array.

string longestCommonPrefix (string arr[], int N)
    {
        
        for(int i=0;i




Remove duplicate element from sorted Linked List  :- Given a singly linked list consisting of N nodes. The task is to remove duplicates (nodes with duplicate values) from the given list (if exists).
Note: Try not to use extra space. The nodes are arranged in a sorted way.


Node *removeDuplicates(Node *head)
{
    Node*temp1=head;
    Node*temp2=head->next;
    while(temp2!=NULL)
    {
        if(temp1->data==temp2->data)
        {
            temp1->next=temp2->next;
            temp2=temp2->next;
        }
        else{
            temp1=temp1->next;
            temp2=temp2->next;
        }
    }
    return head;
}
Find Transition Point :- Given a sorted array containing only 0s and 1s, find the transition point, i.e., the first index where 1 was observed, and before that, only 0 was observed.

 
    int transitionPoint(int arr[], int n) {
        for(int i=0;i

Post a Comment

0 Comments