You are on page 1of 8

Questions(python)

What is the output of the following code snippet? def foo(x, y=[]):
y.append(x)
return y

print(foo(2))
print(foo(3))

What will be the output of the following code snippet? x = [1, 2, 3]


y=x
z = x[:]
y.append(4)
print(len(z))

Write a function to reverse a string without using built-in reverse functions.

How to implement a function to check if two strings are anagrams of eachother.def is_anagram(string1, string2):
return sorted(string1.lower()) == sorted(string2.lower())
Write a Python function to check if a string is a pangram (contains all the letters of the alphabet).
Questions(SQL)

Explain the concept of a self-join in SQL and provide an example query.

What is a recursive SQL query and when would you use it?

Explain the concept of index fragmentation and its impact on database performance.
Explain the concept of query optimization in SQL and discuss techniques to improve query performance.

Explain the concept of database locking and discuss different types of locks in SQL.
Questions(Power BI)

Explain the concept of calculated measures in Power BI?

What is the difference between calculated columns and calculated measures in Power BI?
Explain the concept of data modeling in Power BI?

How can you implement row-level security in Power BI?

How can you optimize the performance of Power BI reports and dashboards?
Answer Explanation

File "main.py", line 2

y.append(x)

IndentationError: expected give space for 2 and 3 line. The output


an indented block is [2] and [2, 3]

The [:] syntax creates a shallow copy of


the list x. It means that z has the same
elements as x, but it is a separate list in
3 memory.

def
reverse_string(input_string):
reversed_string = ""
for i in
range(len(input_string) - 1, -
1, -1):
reversed_string +=
input_string[i]
return reversed_string
input_str = "Hello, World!"
reversed_str = !dlroW ,olleH
reverse_string(input_str)
print(reversed_str) The function iterates over the input
input_str = "Hello, World!" string in reverse order and constructs a
reversed_str = new string by appending the characters
reverse_string(input_str) from the last index to the first index,
print(reversed_str) effectively reversing the string.

string1 = "listen"
This is the function string2 = "silent"
declaration. It takes in two
parameters, string1 and if is_anagram(string1, string2):
string2, which represent the print("The strings are anagrams.")
two strings we want to else:
check for an anagram print("The strings are not
relationship. anagrams.")
import string

def
is_pangram(input_string):
alphabet =
set(string.ascii_lowercase)
letters = In this example, we import the string
set(input_string.lower()) module and create a set alphabet from
string.ascii_lowercase. The resulting set
return letters >= alphabet contains all the lowercase letters of the
input_str = "The quick English alphabet.
brown fox jumps over the
lazy dog" Later in the function, we compare the
set letters (containing the characters
if is_pangram(input_str): from the input string) with the set
print("The string is a alphabet to determine if letters is a
pangram.") superset of alphabet. This comparison
else: helps determine whether the input
print("The string is not a string is a pangram, indicating if it
pangram.") contains all the letters of the alphabet.

SELECT A.CustomerName AS
A self join is a regular join, CustomerName1, B.CustomerName AS
but the table is joined with CustomerName2, A.City
itself. It's basically used FROM Customers A, Customers B
where there is any WHERE A.CustomerID <> B.CustomerID
relationship between rows AND A.City = B.City
stored in the same table. ORDER BY A.City;

if you have a business need to walk or


explode hierarchies in your database,
A recursive query is one that recursive SQL will likely be your most
refers to itself efficient option.

Locating and accessing physically non-


Server index fragmentation contiguous data pages in the disk drive
occurs when the data pages requires more server resources and
in indexes are logically time, resulting in increased query
disordered, loosely filled, or processing time and poor application
overfilled. and server performance.
Tip 1: Add missing indexes
Tip 2: Check for unused indexes
Tip 3: Avoid using multiple OR in the
FILTER predicate

Tip 4: Use wildcards at the end of a


phrase only
Tip 5: Avoid too many JOINs
Tip 6: Avoid using SELECT DISTINCT
Tip 7: Use SELECT fields instead of
SELECT *
Tip 8: Use TOP to sample query
results
SQL Query optimization is Tip 9: Run the query during off-peak
defined as the iterative hours
process of enhancing the Tip 10: Minimize the usage of any
performance of a query in query hint
terms of execution time, the Tip 11: Minimize large write
number of disk accesses, operations
and many more cost Tip 12: Create joins with INNER JOIN
measuring criteria. (not WHERE)

locking is the way that SQL


Server manages transaction
concurrency. Essentially,
locks are in-memory
structures which have Exclusive (X)
owners, types, and the hash Shared (S)
of the resource that it Update (U)
should protect. A lock as an Intent (I)
in-memory structure is 96 Schema (Sch)
bytes in size. Bulk update (BU)

Measures calculate a result from an


expression formula. When you create
your own measures, you’ll use the Data
Analysis Expressions (DAX) formula
using dax language.
columns are row level while measures
aggregations are aggregations
Data modeling is the process of
analyzing and defining all the different
data your business collects and
produces, as well as the relationships
connections between those bits of data.

Row-level security (RLS) with Power BI


can be used to restrict data access for
given users. Filters restrict data access
at the row level, and you can define
Manage roles filters within roles
use filters and min number of quires to
limit the data decrease the load

You might also like