Kumar-laxmi / Algorithms

A Repository for algorithms in C, C++, Python and Java
Apache License 2.0
322 stars 366 forks source link

Add Two pointer Algorithm #732

Closed Gaurang-Agrawal1 closed 1 year ago

Gaurang-Agrawal1 commented 1 year ago

Two pointer : -

The two-pointer technique is a search algorithm used to solve problems involving collections such as arrays and lists by comparing elements pointed by two pointers and updating them accordingly.

Feature : -

Add 2 Pointer Algorithm in C++ , C , java , python.

Description of solution :-

Alternatives Considered :

@Kumar-laxmi Can you please assign me this issue under SSoC'23 so that I can send in a PR on 1st June ?

Kumar-laxmi commented 1 year ago

Could you please provide and sample input-output and related screen shots

poulami02 commented 1 year ago

Hi I have knowledge over C, C++, Python and JAVA and know how to solve pointer operations therefore I would like to work on this issue. I can provide proper documentation and comments in the code. Can you please assign me this issue under SSoC'23? @Kumar-laxmi

SKSADIRUDDIN commented 1 year ago

@Kumar-laxmi Hey, I have good knowledge about 2 pointers. Can you assign me it?

SANKOJUKEERTHI commented 1 year ago

I WOULD LOVE TO CONTRIBUTE TO THIS ISSUE. HAVE GOOD KNOWLEDGE OF JAVA AND CAN PROVIDE OPTIMISED AND GOOD RESULTS.

Vaishu03 commented 1 year ago

@Kumar-laxmi I would love to work on this issue under SSOC'23, as I had good knowledge about this algorithm, can you assign this task to me?

chandrakethan27 commented 1 year ago

@Kumar-laxmi Can you please assign me this issue i have good knowledge of algorithms

KingpinDk commented 1 year ago

Two Pointer Approach can be applied to a variety of problems involving arrays and linked list data structures. Some most common problems are,

the above case works only for sorted array Time Complexity: O(n) Space Complexity: O(1)

alternately we can explicitly sort the array which would cause Time Complexity: O(n log n) //sort function Space Complexity: O(1)

"IF YOU WANT TO ME TO MAKE SOLUTIONS FOR ALL THE PROBLEMS THAT COME UNDER TWO POINTER APPROACH , I CAN MAKE IT AS WELL IN ALL THESE LANGUAGES(JAVA, PYTHON, C, C++). MY SOLUTIONS WILL BE EFFICIENT AND READABLE. GRANT ME THIS ISSUES AND GET A PACKAGE OF EFFICIENT SOLUTIONS FOR PROBLEMS THAT COMES UNDER TWO POINTER APPROACH" Screenshot (81)

ashif88 commented 1 year ago

Can you please assign me this issue i have good knowledge of algorithms. I have solved 900+ DSA Problems in various Coding Platforms. I have solved many problems of two pointer algorithms.

  1. Knight badge on Leetcode
  2. 4 Star on Codechef
  3. Specialist on Codeforces
AK3847 commented 1 year ago

@Kumar-laxmi I have a good knowledge around this topic as I am doing Competitive coding for quite some time now and have solved many question based on this algorithm so can you kindly assign me this issue?

  1. 4 Star on Codechef
  2. Specialist on Codeforces

Thanks for consideration!

Veena4512 commented 1 year ago

@Kumar-laxmi I can implement in python. I'm proficient in python and I participate in various coding competitions. So can you please assign it to me?

swastik-akhil commented 1 year ago

I can do it in Java @Kumar-laxmi

shravanii2308 commented 1 year ago

Can you assign this issue to me @Kumar-laxmi i can do it in C,C++ and python

Gaurang-Agrawal1 commented 1 year ago

Could you please provide and sample input-output and related screen shots

okk @Kumar-laxmi here is the explanation

Two pointer :-

Here is the code with Output :-

// Using Two-pointers Technique import java.util.*; class TwoPointer {

public static int findingSum(int arr[], int N, int X)
{
    // first pointer
    int i = 0;
    //second pointer
    int j = N - 1;
    while (i < j) {
        // checking a pair
        if (arr[i] + arr[j] == X)
            return 1;

        else if (arr[i] + arr[j] < X)
            i++;

        else
            j--;
    }
    return 0;
}
   //Main class input
public static void main(String[] args)
{
    int arr[] = {1, 2, 3,4, 5, 6,};
    int val = 9;
    int arrSize = arr.length;
    System.out.println(findingSum(arr, arrSize, val));
}

}

Output 1 :-

Output

Example 2- In this target is 29 which does not exist , so output is 0 .

Output 2

So, this is the explanation @Kumar-laxmi please assign this issue to me , now I have completely explained it.

Kumar-laxmi commented 1 year ago

Please don't raise LeetCode, GFG or HackerRank, etc