Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1860 of 2650
452 Views
Suppose we have a nested list of integers; we have to implement an iterator to flatten it. Each element is either an integer, or a list. The elements of that list may also be integers or other lists. So if the input is like [[1, 1], 2, [1, 1]], then the output will be [1, 1, 2, 1, 1]To solve this, we will follow these steps −In the initializing section, it will take the nested list, this will work as follows −set res as empty list, index := 0, call getVal(nestedList)The getVal() will take nestedIntegers, this will work as −for ... Read More
449 Views
Suppose one thief has found himself a new place for his thievery again. There is only one entrance to this area, the entrance is called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief felt that "all houses in this place forms a binary tree". And It will automatically contact the police if two directly-linked houses were broken into on the same night. We have to find the maximum amount of money the thief can rob tonight without alerting the police. So if the tree is like −Then the ... Read More
351 Views
We have to create one function to find the nth super ugly number. The super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. So if the n is 12 and primes are [2, 7, 13, 19], then the output will be 32, this is because [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of 12 super ugly numbers.To solve this, we will follow these steps −Create a data structure triplet, with num, prime and idxif n is 1, then return 1, create ... Read More
367 Views
Suppose there are a total of n courses, these are labeled from 0 to n-1. Some courses may have prerequisites, given the total number of courses and a list of prerequisite pairs, we have to find the ordering of courses that we should take to finish all courses. There may be multiple correct orders, we just need to find one of them. If it is impossible to finish all courses, then return an empty array.So if the input is like 2, [[1, 0]], then the result will be [0, 1]. There are a total of 2 courses to take. To ... Read More
1K+ Views
Suppose there are a total of numCourses courses we have to take, labeled from 0 to numCourses-1. Some courses may have prerequisites, for example to take course 0 we have to first take course 1, which is expressed using a pair: [0, 1]. Suppose there are total number of courses that is provided and a list of prerequisite pairs, we have to check whether is it possible for you to finish all courses?So if the input is like − numCourses = 2 and prerequisites = [[1, 0]], then the result will be true, because there are a total of 2 ... Read More
880 Views
Suppose we have two words (beginWord and endWord), and we have dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that −Only one letter can be converted at a time.In each transformed word must exist in the word list. The beginWord is not a transformed word.We have to keep in mind that −Return 0 when there is no such change sequence.All words have the same length.All words contain only lowercase characters.We can assume no duplicates in the word list.So if the input is like: beginWord = "hit", endWord = "cog", and wordlist = ["hot", ... Read More
270 Views
In this tutorial, we will be discussing a program to understand coroutines in C/C++.Coroutines are control instructions which switch the execution control between two routines which returning any of them.Example Live Demo#include int range(int a, int b){ static long long int i; static int state = 0; switch (state){ case 0: state = 1; for (i = a; i < b; i++){ return i; //returning control case 1:; //resuming control } } state = 0; return 0; } int main(){ int i; for (; i=range(1, 5);) printf("control at main :%d", i); return 0; }Outputcontrol at main :1 control at main :2 control at main :3 control at main :4
225 Views
In this tutorial, we will be discussing a program to create a C/C++ code formatting tool with the help of clang tools.SETUPsudo apt install python sudo apt install clang-format-3.5Then we will create a python file in location where the current user has read and write permissions.Exampleimport os cpp_extensions = (".cxx", ".cpp", ".c", ".hxx", ".hh", ".cc", ".hpp") for root, dirs, files in os.walk(os.getcwd()): for file in files: if file.endswith(cpp_extensions): os.system("clang-format-3.5 -i -style=file " + root + "/" + file)Create a file formatting file in the top directory of the current user.Outputclang-format-3.5 -style=google -dump-config ... Read More
4K+ Views
Creating a folder or directory on your computer is an important task in programming. A directory is like a container that helps store and organize files. In C and C++, you often need to create directories to store data, logs, or configuration files. Creating directories makes file management easier. For example, if your program needs to store logs, it should check if a "logs" folder exists. If not, it can create the folder automatically, so you don't have to do it manually. In this article, we'll show you how to create a directory in C or C++. Creating Directories ... Read More
134 Views
In this tutorial, we will be discussing a program to count distinct consecutive sub-string of length two using C++ STL.For this we will provided with a string. Our task is to count and print all the unique substrings of length two from the given string.Example Live Demo#include using namespace std; void calc_distinct(string str){ map dPairs; for (int i=0; i