Giter Club home page Giter Club logo

coding-ninjas-competitive-programming's Introduction

coding-ninjas-competitive-programming's People

Contributors

halfway-there1 avatar hmmonotone avatar imgbotapp avatar jaskirathhh avatar nirbhayjain20 avatar parasjain2792 avatar parikshit223933 avatar pratikbarve09 avatar rathorespaarth avatar ritikagarwal231 avatar rohankumar01 avatar subham142 avatar tewatia5355 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coding-ninjas-competitive-programming's Issues

Warning

warning: control may reach end of non-void function

Fixed failing testcase...optimised the code for 1<=N<=1000

/* Its Gary's birthday today and he has ordered his favourite square cake consisting of '0's and '1's . But Gary wants the biggest piece of '1's and no '0's . A piece of cake is defined as a part which consist of only '1's, and all '1's share an edge with eachother on the cake. Given the size of cake N and the cake , can you find the size of the biggest piece of '1's for Gary ?
Constraints :
1<=N<=1000
Input Format :
Line 1 : An integer N denoting the size of cake
Next N lines : N characters denoting the cake
Output Format :
Size of the biggest piece of '1's and no '0's
Sample Input :
2
11
01
Sample Output :
3 */

int count_ones(vector<vector> &arr, int n, int i, int j, bool **visited)
{
int count = 1;
if (i > 0 && !visited[i - 1][j] && arr[i - 1][j] == 1) //up
{
visited[i - 1][j] = true;
count += count_ones(arr, n, i - 1, j, visited);
}
if (j > 0 && !visited[i][j - 1] && arr[i][j - 1] == 1) //left
{
visited[i][j - 1] = true;
count += count_ones(arr, n, i, j - 1, visited);
}
if (i < n - 1 && !visited[i + 1][j] && arr[i + 1][j] == 1) //down
{
visited[i + 1][j] = true;
count += count_ones(arr, n, i + 1, j, visited);
}
if (j < n - 1 && !visited[i][j + 1] && arr[i][j + 1] == 1) //right
{
visited[i][j + 1] = true;
count += count_ones(arr, n, i, j + 1, visited);
}
return count;
}

int getBiggestPieceSize(vector<vector> &arr, int n) {
// Write your code here
int maximum=0;
bool **visited = new bool *[n];
for (int i = 0; i < n; i++)
{
visited[i] = new bool[n];
for (int j = 0; j < n; j++)
{
visited[i][j] = false;
}
}

    for (int i = 0; i < n; i++)
{
    for (int j = 0; j < n; j++)
    {
        if (arr[i][j] == 1 & !visited[i][j])
        {
            visited[i][j] = true;
            int current_maximum = count_ones(arr, n, i, j, visited);
            if (current_maximum > maximum)
            {
                maximum = current_maximum;
            }
            // for (int p = 0; p < n; p++)
            // {
            //     for (int q = 0; q < n; q++)
            //     {
            //         visited[p][q] = false;
            //     }
            // }
        }
    }
}
return maximum;

}

Intuitive solution for Pair sum to zero in language tools and time complexity module

/* Given a random integer array A of size N. Find and print the pair of elements in the array which sum to 0.
Array A can contain duplicate elements.
While printing a pair, print the smaller element first.
That is, if a valid pair is (6, -6) print "-6 6". There is no constraint that out of 5 pairs which have to be printed in 1st line. You can print pairs in any order, just be careful about the order of elements in a pair.
Input format :
Line 1 : Integer N (Array size)
Line 2 : Array elements (separated by space)
Output format :
Line 1 : Pair 1 elements (separated by space)
Line 2 : Pair 2 elements (separated by space)
Line 3 : and so on
Constraints :
0 <= N <= 10^4
Sample Input:
5
2 1 -2 2 3
Sample Output :
-2 2
-2 2 */

#include<bits/stdc++.h>
using namespace std;
int pairSum(int arr, int n) {
int count=0;
unordered_map<int,int> m;
for(int i=0;i<n;i++){
m[arr[i]]+=1;
}
for(int i=0;i<n;i++){
if(arr[i]==0) continue; // we will handle 0 seperately
int pos = m[arr[i]];
int neg = m[-arr[i]];
if(pos >0 && neg >0){
count = count + (pos
neg);
m[arr[i]]=0;
m[-arr[i]]=0;
}
}
//handle 0 elements
int zeroes = m[0];
count = count + (zeroes*(zeroes-1))/2;
return count;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.