Relative Content

Tag Archive for cdsa

Why is this code which should print the pascal’s triangle not working?

#include <bits/stdc++.h> using namespace std; void solve(vector<vector<long long>> &answer, vector<long long> first, int n) { if (n == 0) { return; } vector<long long> second; for (int i = -1; i < first.size(); i++) { if (i == -1) { second.push_back(first[0]); continue; } if (i == first.size() – 1) { second.push_back(first.back()); continue; } long long […]

Memory limit exceeded in leetcode issue

i was trying to solve this problem on leetcode. its question 169 where i have to return if number from the array if its frequency of occuring in the array is more than half the size of the array.
Input: nums = [3,2,3]
Output: 3
Input: nums = [2,2,1,1,1,2,2]
Output: 2
but i wrote the solution and i am getting memory limit exceeded and i dont know why can youplease help me with this?

can someone tell what’s wrong with my logic?

PROBLEM LINK : https://www.hackerearth.com/practice/data-structures/trees/binary-search-tree/practice-problems/algorithm/monk-and-his-friends/?fbclid=IwAR1n1FJUNpWIeq7dHY-HytoqqE1nbK9gD4jMjI2UWGTPE8GF4kHROCb7ouA
MY SOLUTION : MY CODE WHICH IS DISPLAYING WRONG ANSWERS

a simple coding problem in c# calculate onetwosum

given a string input like 1+1+3-4+3, calculate the result of this expression.
Can someone suggest an approach on how to tackle this problem?
Assumption numbers can be 0-99 and use only two operators + and –

minor compiling error in c++ in function return

QUESTION:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.