1. Practice Problems on Array
1. Write a Swift program to check if 5 appears as either the first or last element in a given array of
integers. The array length should be 1 or more.
2. Write a Swift program to check whether the first element and the last element of a given array of
integers are equal. The array length must be 1 or more.
3. Write a Swift program to test if two given arrays of integers have the same first and last element.
Both arrays length must be 1 or more.
4. Write a Swift program to compute the sum of all the elements of a given array of integers and
length 4.
5. Write a Swift program to rotate the elements of an array of integers to left direction. Therefore {1,
2, 3} yields {2, 3, 1}.
6. Write a Swift program to create a new array with the elements in reverse order of a given array of
integer
7. Write a Swift program to find the larger value of a given array of integers and set all the other
elements with that value. Return the changed array.
8. Write a Swift program to compute the sum of the first 2 elements of a given array of integers.
Return 0 if the length of the given array is 0 and return the first element value If the array length is
less than 2.
9. Write a Swift program to create a new array of length 2 containing the middle elements from two
give array of integers and length 3.
10. Write a Swift program to create a new array of length 2 containing the first and last elements
from a given array of integers. The given array length must be 1 or more.
11. Write a Swift program to test if an array of integers contains a 3 or a 5.
12. Write a Swift program to test if an array of integers does not contain a 3 or a 5.
13. Write a Swift program to create a new array with double the length of a given array of integers
and its last element is the same as the given array. The given array will be length 1 or more. By
default, a new integer array contains all 0's.
14. Write a Swift program to check if a given array of integers contains 3 twice, or 5 twice.
15. Write a Swift program to check if two given arrays of integers have 0 as their first element.
16. Write a Swift program to compute the sum of the values of two given array of integers and each
length 2. Find the array which has the largest sum and return the first array if the sum of two given
arrays are equal.
17. Write a Swift program to create an array of length 2 containing the middle two elements from a
given array of integers and even length 2 or more.
18. Write a Swift program to test if an array of length four containing all their elements from two
given array (each length two) of integers,
2. 19. Write a Swift program to swap the first and last elements of a given array of integers. Return the
modified array (length will be at least 1).
20. Write a Swift program to create a new array of length 3 containing the elements from the
middle of a given array of integers and length will be at least 3.
21. Write a Swift program to find the largest value from the first, last, and middle values in a given
array of integers and length will be at least 1.
22. Write a Swift program to create a new array, taking first two elements from a given array of
integers. If the length of the given array is less than 2 use the single element of the given array.
23. Write a Swift program to create a new array taking the first element from two given arrays of
integers. If either array is length 0, ignore that array.
24. Write a Swift program to count the number of even integers in the given array.
25. Write a Swift program to find the difference between the largest and smallest values in a given
array of integers and length 1 or more.
26. Write a Swift program to compute the sum of the numbers of a given array of integers except
the number immediately after a 11.
27. Write a Swift program to check if a given array of integers contains a 3 next to a 3 somewhere.
28. Write a Swift program to test if the number of 1's is greater than the number of 3's of a given
array of integers.
29. Write a Swift program to test if every element is a 2 or a 5 of a given array of integers.
30. Write a Swift program to check if a given array of integers contains no 2's or it contains no 5's.
31. Write a Swift program to check if a given array of integers contains a 3 next to a 3 or a 5 next to
a 5, but not both.
32. Write a Swift program to test if a given array of integers contains two 5's next to each other, or
there are two 5's separated by one element.
33. Write a Swift program to test if there is a 1 in the array with a 3 somewhere later in a given array
of integers.
34. Write a Swift program to test if a given array of integers contains either 2 even or 2 odd values
all next to each other.
35. Write a Swift program to test if the value 5 appears in a given array of integers exactly 2 times,
and no 5's are next to each other.
36. Write a Swift program to test if every 3 that appears in a given array of integers is next to
another 3.
37. Write a Swift program to test if a given array of integers contains three increasing adjacent
numbers.
38. Write a Swift program to create a new array that is left shifted from a given array of integers. So
[11, 15, 13, 10, 45, 20]