C++ Program for Queries for Rotation and Kth Character of Given String in Constant Time

Shubham Vora
Updated on 24-Aug-2023 16:22:24

165 Views

In this problem, we need to perform the given queries on the string. We can solve the problem by making the rotations of the string differently and accessing the required characters using their index. Problem statement – We have given string str of length N and array ‘que’ of size M containing queries. We need to perform the queries given in the array according to the below conditions. (1, x) – Make x left rotations of the string. (2, x) – Show the xth character in the output. Sample examples Input que[][2] = {{1, 2}, {2, 1}, ... Read More

Concatenate Two Strings in Python

pawandeep
Updated on 24-Aug-2023 16:21:09

37K+ Views

Concatenating two strings refers to the merging of both the strings together. Concatenation of “Tutorials” and “Point” will result in “TutorialsPoint”.We will be discussing different methods of concatenating two strings in Python.Using '+' operatorTwo strings can be concatenated in Python by simply using the '+' operator between them.More than two strings can be concatenated using '+' operator.Example Live Demos1="Tutorials" s2="Point" s3=s1+s2 s4=s1+" "+s2 print(s3) print(s4)OutputTutorialsPoint Tutorials PointUsing % operatorWe can use the % operator to combine two string in Python. Its implementation is shown in the below example.Example Live Demos1="Tutorials" s2="Point" s3="%s %s"%(s1, s2) s4="%s%s"%(s1, s2) print(s3) print(s4)OutputTutorials Point TutorialsPointThe %s denotes ... Read More

Check Whether a Sentence is Tautogram or Not

Shubham Vora
Updated on 24-Aug-2023 16:19:24

143 Views

In this problem, we need to check whether the given sentence is tautogramic. We can say any sentence is tautogramic if all words have the same starting character. We will learn two approaches to solving the problem. The logic to solve the problem is to check all words' first characters. If any word has a mismatched first character, we can say the sentence is not tautogramic. Problem statement – We have a string containing the N characters. We need to check whether the given string is tautogramic or not. Note – The tautogramic contains all words starting with the same ... Read More

Wrap Python Object in C/C++

Gireesha Devara
Updated on 24-Aug-2023 16:01:06

538 Views

To wrap existing C or C++ functionality in Python, there are number of options available, which are: Manual wrapping using PyMethodDef and Py_InitModule, SWIG, Pyrex, ctypes, SIP, Boost.Python, and pybind1. Using the SWIG Module Let’s take a C function and then tune it to python using SWIG. The SWIG stands for “Simple Wrapper Interface Generator”, and it is capable of wrapping C in a large variety of languages like python, PHP, TCL etc. Example Consider simple factorial function fact() in example.c file. /* File : example.c */ #include // calculate factorial int fact(int n) ... Read More

Calculate Server Loads Using Round Robin Scheduling

Prabhdeep Singh
Updated on 24-Aug-2023 15:57:59

899 Views

Round robins scheduling is used in CPU scheduling, we are given some M number of servers and N number of requests. Each request has some arrival time and processing time. We have to find the load on each server using the Round-Robin Scheduling for which we are going to implement a program in C++ programming language using the priority queue and sets. Example Let's understand the problem with the help of an input-output example − Input int arrival_time[] = { 1, 2, 4, 6 }; int process_time[] = { 6, 1, 2, 2 }; int servers = 2; Output ... Read More

Generate Linked List of Maximum Difference of Squares from Given Linked List

Prabhdeep Singh
Updated on 24-Aug-2023 15:56:44

103 Views

A linked list is a linear data structure that consists of nodes and each node is not present in the contiguous form in the main memory, instead, each node contains the address of the next node. We are given a linked list of even length, we have to create a new linked list that contains half number of nodes as the given node, and the value of each node contains the difference between the square of the nodes of the given linked list in decreasing order. Example Let's understand the problem with the help of an input-output example − ... Read More

Dumping Queue into List or Array in Python

Prabhdeep Singh
Updated on 24-Aug-2023 15:54:25

473 Views

A queue is a linear data structure that works on the FIFO property where each element is added to the queue from the rear and the elements are extracted from the front and use the principle of first in first out. In the list, we can access every element while in the queue we can only access the first element. In this tutorial, we are going to see two methods of how to convert a queue into the list. Creating a Queue in Python Queue in a linear data structure which works on the first in first out property and ... Read More

K-th Smallest Element in an Unsorted Array Using Priority Queue

Prabhdeep Singh
Updated on 24-Aug-2023 15:53:20

585 Views

A priority queue is a heap-based data structure, stores elements in such a way that the greatest or smallest element always be present on the top. We are given an array that is unsorted and we have to find the Kth smallest element from it using the Priority Queue. Here, the element k will be given and it must be in the range from 1 to the size of the given array. Example Let's understand the problem with the help of an input-output example − Input int arr[] = {1, 5, 6, 2, 3, 6, 7, 9, 12, 15, 0, ... Read More

Update Python Tuple Element Value

Gireesha Devara
Updated on 24-Aug-2023 15:52:50

1K+ Views

Python tuple is an immutable object, which means once tuple is created you cannot change, update, add, or remove its values. If we try to update any of its elements, then it will throw the TypeError. In this article, we will use three different ways like list conversion, slicing, packing, and unpacking to modify a tuple without raising any errors. Using list conversion By converting tuple to a list then converting it back, we can update the values in tuple, but this will create a list copy of tuple in memory. Example After converting the tuple to list, we ... Read More

Find the Winner of Game by Removing First Character from String

Prabhdeep Singh
Updated on 24-Aug-2023 15:51:29

112 Views

In this game, we are given an array of strings of length N. Each string consists of the digits 1 to N only. The game starts with the first person and removes the first character of the 0th index, then the removed character from the string digit number player will go for the next move. Each player with index y will remove the digit from the string from index y-1 and then the remove digit number player will move next. When any player is not able to remove the character will win the game. Example Let's understand the problem with ... Read More

Advertisements