V

@vikash2162

Find the 'SUM' of a 'contiguous' subarray within an array of numbers that has the LARGEST sum

PHP
2 years ago
<?php //Find the 'SUM' of a 'contiguous' subarray within an array of numbers that has the LARGEST sum. Array is [-2, -3, 4, -1, -2, 1, 5, -3]. //Meaning of 'Contiguous Subarray': Any sub series of elements in a given array that are contiguous ie //their indices are continuous. //So given [1,2,3,4,5,6]:[1,2,3], [3,4], [3,4,5,6] are all valid contiguous subarrays

There is a sorted array with unique elements of length n. Return all the PAIRS possible that when a

PHP
2 years ago
<?php //There is a sorted array with unique elements of length n. //Return all the PAIRS possible that when added gives you Y. //Sample Array: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] . (Y=110) // 0 , 1, 2, 3, 4, 5, 6, 7, 8, 9 //$arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]; $arr = [-10, -5,0,10, 15, 30, 35, 45, 60, 70, 80, 90, 100]; $sumofPair = 20;

Binary search

PHP
2 years ago
<?php $arr = [7,10,15, 23, 25,40,55,78,98]; $search_element = 1; $end = count($arr) -1;//6 $start = 0; //If mid > element, traverse left OR mid < element, traverse right $found = 0; //echo count($arr)." ".$start; while($end >= $start){

Reverse a string by word: 'geeks quiz practice code' Result;- code practice quiz geeks

PHP
2 years ago
<?php $string = 'geeks quiz practice code'; //MEthod 1 $new_str = ''; $str_arr = explode(' ',$string); for($i=count($str_arr)-1;$i >= 0; $i--){ $new_str .= $str_arr[$i]." ";

Reverse a string character by character: 'ONCE UPON A TIME IN MUMBAI' Result;- IABMUM NI EMIT A NOPU

PHP
2 years ago
<?php $string = 'ONCE UPON A TIME IN MUMBAI'; $count_str = strlen($string); $str = ''; for($i=$count_str-1;$i>= 0;$i--){ $str.= $string[$i]; }

Write a program to concatenate two strings character by character. e.g : JOHN + SMITH = JSOMHINTH

PHP
2 years ago
<?php //METHOD 1 $string1 = 'JOHN'; $string2 = 'SMITH'; $count_str1 = strlen($string1); $count_str2 = strlen($string2); if($count_str1 > $count_str2){

Sort an Array

PHP
2 years ago
<?php $arr = [66,4,26,8,0,3,6]; $total = count($arr); //Version 1 for($j=0; $j<$total;$j++){ for($i=$j+1;$i<$total;$i++){ echo $i." ".$j." dfd ";

Overloading using __call in PHP

PHP
5 years ago
<?php class ABC{ function __construct(){ echo 'constructor invoked'; } public function __call($name,$args){

interface example php

PHP
5 years ago
<?php interface paymentMethod{ const DEFAULTPAYMENT = 'visa'; function pay(); } interface paymentMethodNew{

Static properties and methods php

PHP
5 years ago
<?php class Person{ private $name; private $age; private static $ourspecies; public function __construct(){ $this->name = 'Aakash';

PHP trait example

PHP
5 years ago
<?php trait ABC{ public function test(){ echo 'inside ABC trait'; } } trait XYZ{

Merge two sorted arrays(non-efficient solution) php

PHP
5 years ago
<?php $arr1 = [2,2,3,4,7]; $arr2 = [-1,1,2,8,10]; $merged_arr = []; $i = 0; $j = 0; $count_arr1 = count($arr1); $count_arr2 = count($arr2);

Array functions(foreach,map,filter,reduce) Javascript

NodeJS
5 years ago
let arr = [1,9,5,7,8,5,0]; arr.forEach((currvalue,index,arr)=>{ //console.log(currvalue); }) //console.log('Array.forEach') //console.log(arr) let newarr = arr.map((currvalue,index,arr)=> currvalue * 2)

Missing characters to make a string Pangram

PHP
5 years ago
<?php //Eg- Panagram - The quick brown fox jumps over the lazy dog $str = "The quick brown fox jumps over the lazy dog"; $wordarr = array(); for($i=0;$i<strlen($str);$i++){

Pangram Checking

PHP
5 years ago
<?php //Eg- Panagram - The quick brown fox jumps over the lazy dog $str = "Bright vixens jump; dozy fowl quack"; $wordarr = array(); $lettercount = 0; for($i=0;$i<strlen($str);$i++){

reverse a string

PHP
5 years ago
<?php $str = "string to be reverse"; echo $str; echo "\n"; //Output 1 = 'esrever eb ot gnirt' $str_length = strlen($str); $revstr = ''; for($i=$str_length;$i > 0;$i--){

Write a program to concatenate two strings character by character. e.g : JOHN + SMITH = JSOMHINTH

PHP
5 years ago
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $str = "JOHN"; $str1 = "SMITH"; if(strlen($str) >= strlen($str1)){ $strtoloop = $str;