A square has all the four sides as equal length. We can imagine a circle whose centre is one of the corner points of the square and it intersects the square's sides at the middle. We can take any side of a same square or corner point and the area of the circle will be same.
A single odd numbered element in an array is the only element inside that array which does not exist as in an even number of times in the array unlike the other elements.
The goal is to first compute the area of circles from a given pair of coordinate points representing the coordinates of two diagonally opposite points on the square. After getting the list of areas the final goal is to get the area (number) that is present inside the previous list odd number of times and print the value.
Consider the below image. In this figure there are two coordinates(for point A and point C) given. Each circle having a center at each corner point on the square. Each circle intersected two of the squares sides at the middle. We need to find the area of any one of these circles as all the four circles will have the same area.
Given an array of coordinates in two dimensional space represented as list of lists. Each consecutive pairs of coordinates represent the corner points on a square. We need to first calculate all such possible circle areas from it. e.g. [ (-3, 5) , (5, -3), (13, -11), (10, -8)]. The area of circle on the square having (-3, 5) and (5, -3) as their opposite corner points is 28 unit. Similarly, with (5, -3) and (13, -11) it is 28 and with (13, -11) and (10, -8) it is 3. So, the list of circle areas will be [28, 28, 3] and only number 3 has appeared in odd number i.e. 1, hence the answer to be printed is 3 With each computation steps take the floor value. Only the answer should be printed without any other characters in it.
Complete the function findOddCircleArea in the editor below. The function must print only the answer.
findOddCircleArea has the following parameter(s):
coordinates [[xo, yo]l...numbers [xn-1, yn-1]]: an array of integers
• size of the internal list is 2.
• The resultant list of calculated areas will have only one number that appears odd number of times, rest all appears even number of times.
• If the constraint is not satisfied print Invalid Input.
4
2
-3, 5
5, -3
13, -11
10, -8
3
Circle areas computed with the given input is [28, 28, 3]. Number 3 appeared odd number of times i.e. 1. So, the answer will be 3.
In UNIX, the files have special permissions and they are represented using the alphabets t and s. The symbol t is used to represent the Sticky Bit and the symbol s is be used to represent the Set UID BIT and Set GID Bit on the file. The below table represents the octal value for each of them along with the symbol.
Symbol | Octal Value | Name | Represented Where |
t | 1 | Sticky Bit | In place of x of the other permission |
s | 2 | Set GID Bit | In place of x of the group permission |
s | 4 | Set UID Bit | In place of x of the owner permission |
Regular permissions on a file/directory on UNIX are represented in both octal and human readable format. Files/directories can have r (read), w (write) and x (execute) permissions for a set of user. If any of these r, w or x is not present, then it substituted with -. The below table gives the octal value and its equivalent human readable representation.
Octal Value | Readable character |
4 | r |
2 | w |
1 | x |
Now, let assume that the given octal number is 6. Then it can be seen from the above table that it is sum of 4 * 2 = 6. This means that only r and w permissions are available to the file and no execute permission. Therefore, the human readable format for this octal would rw-.
It is important to note that when the executable permission i.e. × is not applied on the file but the special permissions or T is applied, then the special permission are displayed in uppercase letters. Consider an example where the file permission is 1644. Here it can be noticed that the sticky bit to the file whee the × permission is not present. Therefore, the string representation of this file permission would be rw-r--r-T.
Consider the following examples, for the special permissions:
File Permission | Octal Representation | Example for? |
rw-rw-rwt | 1667 | Sticky bit at last position or in place of x permission for other. |
rw-rwsrw- | 2676 | Set GID in place of x permission for group. |
rwsrw-rw- | 4766 | Set UID in place of x permission for owner. |
rwsrw-r-t | 5765 | The special permission on the file has an octal value 5 which is a sum of 4 and 1. Mapping this to the special permission, we find that the Set UID and sticky bit are to be set on the file |
rwxr-Sr-- | 2744 | There is no X permission for the group and set GID is also present. |
Note: The Sticky Bit can be set only on directories. It is not permitted on other file types.
Given the octal permission as the input, find the string representation of the file.
Example. #1
Consider the inputs:
1777
As the input says the input file permission should be having sticky bit permission, therefore based on the tables above, we find the output should be:
rwxrwxrwt
Example #2
Consider another input where there is no spegial permission:
0777
As there is no special permission in the input, therefore based on the tables above the permission would be:
rwxrwxrwx
Function Description
Complete the function parsePermission in the editor below. The function must prin
the permission in the string format.
parsePermission has the following parameter (s):
In the question, it is mentioned that we are given a list of coordinates, in which consecutive coordinates represent the diagonally opposite corners of a square. So, the circle drawn with a corner point of the circle as its center and intersecting with the sides at the middle has diameter equal to the distance between the x-coordinates/y-coordinates, and the radius will be half of it.
Since it is mentioned in the question that we need to find the area of all such circles, we can compute the radii and then put them in a map to count their frequency. This is because the area of circles with different radii will be different, so counting radii inplace of area will make no difference.
Also, say for diameter equal to 6 and diameter equal to 7, the area will be same since we need to take the floor of the radius, so floor(3.5) = 3, and floor(3) = 3. Hence, we need to keep this in mind while calculating the answer.
ll n;
cin > > n;
vector<pair<ll,ll>> a(n);
for(ll i=0;i < n;i++)
cin > > a[i].fi > > a[i].se;
map < ll,ll > freq;
for(ll i=0;i < n-1;i++)
{
ll side = abs(a[i].fi - a[i+1].fi);
ll radius = side/2;
freq[radius]++;
}
ll ans = -1;
for(auto it=freq.begin();it!=freq.end();it++)
{
if(it - > se%2==1)
{
ans = it - > fi;
break;
}
}
cout < < 3*ans*ans < < '\n';