Swap Nodes in Pairs Problem

Problem Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves may be changed.) Examples Example 1: --- title: Input --- graph LR; 1 --> 2:::focus --> 3 -->4:::focus classDef focus fill:#f96 --- title: Output --- graph LR; 2:::focus --> 1 --> 4:::focus -->3 classDef focus fill:#f96 ...

2Sum Problem

Problem You are given an array of n integers and a target sum T. The goal is to determine whether or not there are two numbers x, y in A with x+y=T. OR Given an array of integers, find two numbers such that they add up to a specific target number. Variant: Return the indices instead of the elements in array. Example Example 1: ...

Swap alternate nodes in a singly linked list

Problem Given a single Linked List. Swap every other alternate nodes. Examples Example 1: Input: head = 1 -> 2 -> 3 -> 4 -> 5 -> null Output: 3 -> 4 -> 5 -> 1 -> 2 -> null Explanation: The list was transformed in several steps. 1. First step, swap 1 and 3 i.e. 3–>2–>1–>4–>5–>null 2. Second step, swap 2 and 4 i.e. 3–>4–>1–>2–>5–>null 3. last step, swap 1 and 5, i.e. 3–>4–>5–>2–>1–>null ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy