This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Problem set | |
//Given an unsorted array nums, write a function to find the start and end positions of a given number val in the array after sorting it. | |
const getStartAndEndPosition = (nums,val) =>{ | |
//if nums is empty or null | |
if (!nums || nums.length === 0) { return [-1,-1]}; | |
//sorting the array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Given an integer array nums, | |
//write a function that returns an array products, | |
//such that each entry at position i, in products is a product of all the other elements in nums except num[i] | |
// #algorithm friday set4 | |
const productOfArray = (nums) => { | |
// testing for array or empty array | |
if (!Array.isArray(nums) || nums.length == 0 ) return ' Invalid Input ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Problem Set for #AlgorithmFriday Week5 | |
// A school has two classes A and B, Each class has the ages of its students in a sorted list. | |
// The school decides to join both classes and needs you to help them write a function that merges both lists into one | |
// such that the students' ages still remains sorted in increasing order. | |
const mergeSortedArray = (classA,classB) => { | |
// Test cases for null and empty array | |
if (!Array.isArray(classA) || !Array.isArray(classB) ) return [] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apex college needs your help in writing a logic to shuffle pupils on an assembly line | |
// by moving a number of pupils either to the front of the line or to the end of the line. | |
const shufflePupils = (pupils,val) => { | |
// Test cases for null and empty array | |
if (!pupils || pupils.length == 0) return [] | |
// test case for 0 value | |
if(val == 0) return pupils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sololearn problem set for c++ | |
// You are working on a ticketing system. A ticket costs $10. | |
// The office is running a discount campaign: each group of 5 people is getting a discount, which is determined by the age of the youngest person in the group. | |
// You need to create a program that takes the ages of all 5 people as input and outputs the total price of the tickets. | |
// Sample Input: 55 28 15 38 63 | |
// Sample Output: 42.5 | |
// The youngest age is 15, so the group gets a 15% discount from the total price, which is $50 - 15% = $42.5 | |
#include <iostream> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
Write a function: | |
def solution(A) | |
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. | |
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. | |
Given A = [1, 2, 3], the function should return 4. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
//Function call by reference using pointers | |
void AskForValues(double *a_ptr, double *b_ptr,double *c_ptr) | |
{ | |
cout << endl << "Enter your values" ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
// Function Prototype | |
void FillArray(float ArrayValues[]); | |
void CalculateMeanandStddev(float ArrayValues[], double *Mean_ptr, double *Stddev); | |
void PrintResult(float ArrayValues[], double Mean, double Stddev); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given an array of binary digits, 0 and 1, sort the array so that all zeros are at one end and all ones are at the other. Which end does not matter. To sort the array, swap any two adjacent elements. Determine the minimum number of swaps to sort the array. | |
# Example | |
# arr = [0, 1, 0, 1] | |
# With 1 move, switching elements 1 and 2 yields [0, 0, 1, 1], a sorted array | |
# Function Description | |
# Complete the function minMoves | |
# minMoves has the following parameter(s): |
OlderNewer