Saturday, 4 Dec 2021
Category: Reverse

Given an array arr[] of size N and a value K, the task is to print the array rotated by K times to the right.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your […]

Given a string s. The task is to minimize the number of adjacent swaps required to reverse the string. Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to […]

class LinkedList {          Node head;          class Node {        int data;        Node next;        Node(int d)        {            data = d;            next = null;        }    }      Node reverse(Node node, int k)    {        if (k == 1)            return node;                  Node result = null;                  Node head = new Node(0);        head.next = node;        Node next = node.next;          int count = 0;        while (next != null) {            count++;                                                  Node tmp = next.next;            next.next = node;            node = next;            next = tmp;              if (count == k – 1) {                count […]

#include using namespace std;  class Node {public:    int data;    Node* next;      Node(int x)    {        this->data = x;        this->next = NULL;    }};  Node* reverseList(Node* head){    Node *prev = NULL, *nextNode = NULL;    while (head != NULL) {                          nextNode = head->next;                          head->next = prev;          prev = head;          head = nextNode;    }    return prev;}  Node* Remove_Dup_Keep_Last_Occurence(    Node* head){        Node* dummy = new Node(-1);    dummy->next = head;          dummy->next = reverseList(dummy->next);          unordered_set visited;      Node *currNode = dummy, *nextNode;          while (currNode != NULL           && currNode->next != NULL) […]

Reversing a Stack with the help of another empty StackGiven a Stack consisting of N elements, the task is to reverse the Stack using an extra stack.Examples:Input: stack = {1, 2, 3, 4, 5}Output:12345Explanation:Input Stack:54321Reversed Stack:12345Input: stack = {1, 3, 5, 4, 2}Output:13542Approach: Follow the steps below to solve the problem:Below is the implementation of […]

#include using namespace std;  bool adjust(string& S, int& i,            int& start, int& end){        int N = S.length();              start = i – 1;              while (i < N && S[i] < S[i - 1]) {                  i++;    }              end = i - 1;          if (start = N)        return true;          if (start >= 1 && i = S[start – 1]                && S[start] = 1) {                  return S[end] >= S[start – 1];    }          if (i […]

#include #include #include    struct Node {                  int data;                  struct Node* nxp; };    struct Node* XOR(struct Node* a,                  struct Node* b) {     return (struct Node*)((uintptr_t)(a)                           ^ (uintptr_t)(b)); }    struct Node* insert(struct Node** head,                     int value) {          if (*head == NULL) {                     struct Node* […]

Count of unique pairs (i, j) in an array such that sum of A[i] and reverse of A[j] is equal to sum of reverse of A[i] and A[j] Given an array arr[] consisting of N positive integers, the task is to find the count of unique pairs (i, j) such that the sum of arr[i] […]