Programming Articles

Page 206 of 2544

Count of words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of given word in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 240 Views

We are given a string str[] as input. The goal is to count the words from str[] that have the same length as str[] and have positions of letters such that ith letter is replaced with letter at position (i1) or (i) or (i+1).For the first letter replacement will be from position i or i+1For the last letter replacement will be from position i-1 or i.Let us understand with examples.Input − str[] = “TPP”Output − Count of words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of given word are − 4Explanation Replacing T by T (i)th or 1st ...

Read More

Program to check person can reach top-left or bottomright cell avoiding fire or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 174 Views

Suppose we have a 2D matrix with few different values like below −0 for empty cell1 for a person2 for fire3 for a wallNow assume there is only one person and in each turn the fire expands in all four directions (up, down, left and right) but fire cannot expand through walls. We have to check whether the person can move to either the top-left corner or the bottom-right corner or the matrix. We have to keep in mind that in each turn, the person moves first, then the fire expands. If the person makes it to any of the ...

Read More

How to convert a string vector into title case in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 729 Views

We cannot be sure about the data characteristics we get for analysis and mostly it is not well organised, thus, the first task would be to make it more organised. The string values not in title case should also be taken care of if it is especially supposed to be in title case. For this purpose, we can str_to_title function of stringr package.Example1> x1 x1Output[1] "india" "united kingdom" "indonesia" "canada" [5] "canada" "india" "united kingdom" "canada" [9] "indonesia" "united kingdom" "indonesia" "canada" [13] "russia" "indonesia" "canada" "russia" [17] "united kingdom" "russia" "russia" "india" [21] "united kingdom" "india" "india" "united kingdom" ...

Read More

Find if a number is divisible by every number in a list in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 319 Views

In this problem, we are given a list of n numbers and a number. Our task is to find if a number is divisible by every number in a list. We need to check if the given number divides all elements of the list or not.Let’s take an example to understand the problem, Input: list[] = [4, 10 ,6, 5, 9] num = 5Output: NoExplanation:Elements 4, 6, 9 are not divisible by 5.Solution Approach: To solve the problem, we need to check if any element of the list is divisible by num. If every number of lists is divisible by num, return true else ...

Read More

Program to find maximum profit we can make after k Buy and Sell in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 276 Views

Suppose we have a list of numbers called nums that is representing the stock prices of a company in chronological order and we also have another value k, we have to find the maximum profit we can make from up to k buys and sells (We must buy before sell, and sell before buy).So, if the input is like prices = [7, 3, 5, 2, 3] k = 2, then the output will be 3, as we can buy at 3, then sell at 5, again buy at 2, and sell at 3.To solve this, we will follow these steps ...

Read More

Program to count number of flipping required to make all x before y in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 227 Views

Suppose we have a lowercase string s with letters x and y. Now consider an operation in which we change a single x to y or vice versa. We have to find the minimum number of times we need to perform that operation to set all x's come before all y's.So, if the input is like s = "yxyyyyxyxx", then the output will be 4.To solve this, we will follow these steps −y_left := 0x_right := number of "x" in s, res := number of "x" in sfor each item in s, doif item is same as "x", thenx_right := ...

Read More

Count ways to divide circle using N non-intersecting chords in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 503 Views

Given an integer N as input for a number of chords in a circle with 2*N end points. The goal is to count the ways in which we can divide that circle using such chords so that no chord intersects with each other.For N=3, points will be 6, 1 way of getting 3 chords is between 1−2, 3−4, 5−6Other ways −1−6, 2−5, 3−4 1−2, 3−6, 4−5 1−4, 2−3, 5−6 1−6, 2−3, 4−5Total 5 ways.For ExampleInputN=4OutputCount of ways to divide circle using N non-intersecting chords are: 14ExplanationThere will be a total 8 points between which we can draw chords. After drawing ...

Read More

Find if a string starts and ends with another given string in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 593 Views

In this problem, we are given two strings str and corStr. Our task is to find if a string starts and ends with another given string. Let’s take an example to understand the problem, Input: str = “abcprogrammingabc” conStr = “abc”Output: TrueSolution Approach: To solve the problem, we need to check if the string starts and ends with the conStr. For this, we will find the length of string and corStr. Then we will check if len(String) > len(conStr), if not return false.Check if prefix and suffix of size corStr are equal and check they contain corStr or not.Program to illustrate the working of ...

Read More

Program to evaluate one mathematical expression without built-in functions in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 3K+ Views

Suppose we have a string that represents a mathematical expression with (+, -, *, /) Here / is representing integer division, we have to evaluate and return the result without using any built-in function.So, if the input is like s = "2+3*5/7", then the output will be 4, as 2 + ((3 * 5) / 7) = 4To solve this, we will follow these steps −s := reverse the given stringDefine a function get_value().sign := 1if s is not empty and last element of s is same as "-", thendelete last element from ssign := -1value := 0while s is ...

Read More

How to remove names from a named vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 7K+ Views

To assign names to the values of vector, we can use names function and the removal of names can be done by using unname function. For example, if we have a vector x that has elements with names and we want to remove the names of those elements then we can use the command unname(x).Example1> x1 names(x1) x1OutputG K N V P F F A P D L N K J V H S L F C M F H T I V 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

Read More
Showing 2051–2060 of 25,433 articles
« Prev 1 204 205 206 207 208 2544 Next »
Advertisements