Skip to main content

Alex and his Array code TechGig Geek Goddess 2023

 Alex and his Array code TechGig Geek Goddess 2023:


100% Working Code uploaded on Youtube: https://youtu.be/6cn7nNtSiKo

100% Working Code uploaded on Telegram: https://telegram.me/PLACEMENTLELO


Alex and his array (100 Marks)

Meet Alex, a bright student who is dealing with an array challenge today. He has been given an array a1, a2, ..., aN of length N. The intriguing aspect of this challenge is that Alex can perform various operations on the array elements.

In a single operation, Alex is allowed to choose two indices l and r, where 1 ≤ l ≤ r ≤ n. He can then multiply all the elements in the subarray [al, al+1, ..., ar] by -1, effectively reversing their signs.

Being pressed for time as he is running late for school, Alex is seeking your assistance in determining the maximum possible sum of numbers in the array. Additionally, he is eager to find out the minimum number of operations required to achieve this maximum sum.


Input Format

The first line contains an integer N, the length of the array.

The second line contains N space-separated integers a1, a2, ..., an, the array elements.


Constraints

1 ≤ N ≤ 2 * 10^5

-10^9 ≤ ai ≤ 10^9


Output Format

Print two space-separated integers: the maximum possible sum of integers in the array and the minimum number of operations required to achieve this sum.


Sample TestCase 1

Input

4

-1 0 -2 -1

Output

4 1

Explanation

We should select:

l = 0

r = 3

After one operation,

Array [0, 3] = { 1, 0, 2, 1}

The sum of the array = 1+0+2+1 = 4

Time Limit(X):

0.50 sec(s) for each input.

Memory Limit:

512 MB

Source Limit:

100 KB

Allowed Languages:

C, C++, C++11, C++14, C#, Java, Java 8, Kotlin, PHP, PHP 7, Python, Python 3, Perl, Ruby, Node Js, Scala, Clojure, Haskell, Lua, Erlang, Swift, VBnet, Js, Objc, Pascal, Go, F#, D, Groovy, Tcl, Ocaml, Smalltalk, Cobol, Racket, Bash, GNU Octave, Rust, Common LISP, R, Julia, Fortran, Ada, Prolog, Icon, Elixir, CoffeeScript, Brainfuck, Pypy, Lolcode, Nim, Picolisp, Pike, pypy3


100% Working Code uploaded on Youtube: https://youtu.be/6cn7nNtSiKo

100% Working Code uploaded on Telegram: https://telegram.me/PLACEMENTLELO




Comments

Popular posts from this blog

TechGig Code Gladiators 2023 Coding Solutions

TechGig Open Coding Round Code Gladiators 2023 Answers Round 1  - Problem 1 Forest Fire Coding Solution Figure out the minimum energy level P such that they can get exactly X animals to transport.  Test Case: 5 4  1 3 2 4 5 Output: 2 Coding Solution in Python 3: from bisect import bisect_left #Telegram - @PLACEMENTLELO n, m = map ( int , input ().split()) a = list ( map ( int , input ().split())) a.sort() #Telegram - @PLACEMENTLELO if n - bisect_left(a, a[n-m]) != m: print ( -1 ) else : print (a[n - m]) #Telegram - @PLACEMENTLELO ------------------------------------------- Round 2  - Problem 2 The Magic Coding Solution The cost of using wand for operation on element equal to absolute difference between value of element and desired value after operation. Test Case: 5 3 1 2 3 4 5 5 2 1 Output: 10 7 10 Coding Solution in Python 3: from bisect import bisect_left #Telegram - @PLACEMENTLELO n, m = map ( int , input ().split()) A = list ( map ( int , input ().split())) Q = list

The Divisibility Dilemma Code Techgig Geek Goddess Solution

The Divisibility Dilemma Code Techgig Geek Goddess Solution 100% Working Code uploaded on Youtube: https://youtu.be/6cn7nNtSiKo 100% Working Code uploaded on Telegram: https://telegram.me/PLACEMENTLELO The Divisibility Dilemma (100 Marks) In the picturesque village of Numeropolis, the annual "Divisibility Day" is celebrated with great enthusiasm. This day is marked by various mathematical challenges and games that put the villagers' arithmetic skills to the test. This year, the villagers are embarking on a quest to explore the distinctive properties of subarrays within integer arrays. The village's renowned mathematician, Professor Arithmo, has crafted an intriguing challenge. He has provided the villagers with an integer array nums`and two additional integers, K and P. Professor Arithmo's challenge revolves around discovering and counting distinct subarrays from the array nums. The uniqueness of these subarrays is determined by their divisibility characteristics.

Google Girl Hackathon 3 June 2023 Solutions

Google Girl Hackathon 3 June 2023 Solutions Google Girl Hackathon 2023   Maximize equal numbers Code in Python Task Determine the maximum length of the subsequence of array a, such that all numbers in that subsequence are equal after applying the given operation. Code in Python def MaximizeEqualNumber(n, k, a):     #Telegram - @PLACEMENTLELO     max_length = 0     for i in range(n):     #Telegram - @PLACEMENTLELO         count = 1          for x in range(-k, k+1):     #Telegram - @PLACEMENTLELO             if a[i] + x in a[i+1:]:                 count += 1     #Telegram - @PLACEMENTLELO         max_length = max(max_length, count)     return max_length n = 4 k = 1 a = [2, 5, 1, 2] # Output: 3 n = 4 k = 0 a = [2, 2, 5, 6] # Output: 2 n = 3 k = 2 a = [1,5,6] # Output: 2 That is Perfection Code in Python  def is perfect number (n):      divisors_sum = sum(i for i in range(1, n) if n % i == 0)      return divisors_sum == n Balanced Brackets You are given a string S of length N. It consists