0% found this document useful (0 votes)
4 views2 pages

Sample Problems

The document outlines a series of programming tasks and functions that involve basic operations on integers and strings, such as calculating sums, finding factors, converting cases, and manipulating arrays. It includes examples and specifications for functions that handle tasks like summing digits, identifying odd/even numbers, merging sorted arrays, and counting unique elements. Additionally, it describes how to create a target array based on given indices and values.

Uploaded by

iptvtesttrack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Sample Problems

The document outlines a series of programming tasks and functions that involve basic operations on integers and strings, such as calculating sums, finding factors, converting cases, and manipulating arrays. It includes examples and specifications for functions that handle tasks like summing digits, identifying odd/even numbers, merging sorted arrays, and counting unique elements. Additionally, it describes how to create a target array based on given indices and values.

Uploaded by

iptvtesttrack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sample Probelms

Write a function that takes as input an integer number, n, and displays the sum of integer numbers from 1
to n-1. For example, n= 5, output: 10 (4+3+2+1)
Write a function that takes as input an integer number, n, and displays all the positive factors of n
(excluding n itself) and returns the sum of them. For example: n=12, Output = 1, 2, 3, 4, 6 return 16.

Write a function that takes as input an integer number, n, and converts it to a string and display it.
Write a function that takes two input parameters, a string, and its size (integer), and returns 1 if the first
character of the given string is uppercase, returns 0 if it is lowercase, and returns -1 if it is a digit.
Write a function that takes an integer as input and returns the sum of all its digits.
Write a program to read input values for an integer list of size 15 and display the second largest integer
value in the array.
Write a function that takes as input an integer and returns 1 if it is odd and returns 0 if it is even.
Write a program to read a lowercase character and convert it into the corresponding uppercase character.
Write a function that takes two string as input and returns 1 if they are equal and otherwise returns 0. Two
strings are considered equal if both contain the same number of elements, and all corresponding
pairs of elements are equal in the same order.
Write a program that reads ten integer numbers from the user and stores them in a list of size 10. Then
counts and displays the sum of the odd numbers which are in the even index positions of the list.
Write a function, distance, that receives four double floating-point numbers, 𝒙𝟏, 𝒚𝟏, 𝒙𝟐, and 𝒚𝟐. This
function should compute and return the custom distance of two points with the coordination (𝒙𝟏, 𝒚𝟏) and
(𝒙𝟐, 𝒚𝟐), using the equation 𝒅 = *(𝒙𝟐 − 𝒙𝟏)𝟓 + (𝒚𝟐 − 𝒚𝟏)𝟓.

Write a program that reads an arbitrary number of integers that are in the range -50000 to 5000000 from
the user and a), displays them in the ascending order, b) displays the biggest value, and c) displays the
average of these numbers.

Two Sum:
Write a function that receives a list of integers, its size, an integer target and an empty list of two integers.
The function should update the empty list with indices of the two numbers in the first array 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.

Merge two sorted array:


Write a function that receives two sorted lists of integers, and their sizes. The function should create a new
sorted list including all the elements of the two array parameters.
Count Elements:
Write a function that receives a list of integers, and its size. The function should print out each unique
element and its frequency to the screen.
Shuffle the array:
Write a function that receives a list consisting of 2n integer elements in the form
[x1,x2,...,xn,y1,y2,...,yn], and its size, and it updates the list in the form [x1,y1,x2,y2,...,xn,yn]
Number of Good Pairs:
Write a function that receives a list of integers. The function should return the number of good pairs. A
pair (i,j) is called good if nums[i] == nums[j] and i < j.
Create Target Array in the Given Order:
Write a function that receives two list of integers nums and index. The function should create a target list
and print out its elements under the following rules:
Initially target list is empty.
From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target list.
Repeat the previous step until there are no elements to read in nums and index.
Return the target list.
Example:
Input: nums = [0,1,2,3,4], index = [0,1,2,2,1]
Output: [0,4,1,3,2]
Explanation:

nums index target


0 0 [0]
1 1 [0,1]
2 2 [0,1,2]
3 2 [0,1,3,2]
4 1 [0,4,1,3,2]

You might also like