Skip to content
W3colleges

W3colleges

  • Home
  • Algorithms
    • Analysis of Algorithms
    • Searching
    • Sorting
    • Divide and Conquer
    • Greedy
    • Dynamic Programming
    • Backtracking
    • Branch and Bound
    • Graph And Algorithms
    • Pattern Searching
    • Mathematical
    • Geometric
  • Data Structures
    • Array
    • Queue
    • Stack
    • Linked List
    • Binary Tree
    • Graph
    • Hashing
    • String
  • C Programming
    • Basic
    • Pointers
    • Operators
    • Control Statement
    • Loops
    • Function
    • Array
    • Sorting
    • Advanced
  • C++ Programming
    • C++ Basics
    • Operators
    • Control Statements
    • Functions
    • Array
    • Constuctor and Destructor
    • Overloading & overriding
    • C++ Library
    • STL
    • Misc
      • Object Oriented
      • Inhertiance
      • Sorting
      • Advanced
  • Programs
    • C Programs
    • C++ Programs
  • CS Core
    • Operating Systems
    • DBMS
    • Computer Networks
  • Interviews
  • Contests
  • Python

Find sum of all n digits which come in power of 2 of given number n

Problem: Given an integer ‘n’, find sum of all n digits which come in power of 2 of given number n. Examples: Input: p = 9 Output: 8 Explanation : 2^9 = 512 Digit sum : 5 + 1 + 2 = 8 Input: p = 48 Output: 73 Explanation : 2^48 = 281474976710656 Digit sum : 73… Read More »

Java Programs Mathematical

Sum of Fibonacci Series

The first few terms(Fn) of Fibonacci Numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, … For given N find the sum (Sn) of 0 to nth term of a fibonacci series. Sn = Fn+ Fn-1+ …+ F1+ F0 // Naive Method Sn = Fn+2 – 1 // Advanced method Examples:… Read More »

C++ Programs Mathematical
Fibonacci Series Sum

Print all the perfect squares in a range

Print all the perfect squares in a range i.e. a and b are the lower and upper bounds respectively. So print all the perfect squares between them and both are inclusive. Examples: Input: a = 1, b = 10 Output: 1, 4, 9 Input: a = 10, b = 100 Output: 16, 25, 36, 49, 64, 81, 100… Read More »

Arrays C++ Programs Mathematical

Find Minimum Inversions on a Chessboard Grid

Given a n*m chess board. We can choose any rectangle formed by board squares and perform an inversion. Every white cell in the inverted rectangle becomes black and every black one becomes white. In the initial state the board is colored in chess style, namely every cell is either black or white and every two cells that share… Read More »

Arrays Mathematical Python Programs
Inversions

First N natural can be divided into two sets with given difference and co-prime sums

Given first N natural numbers. Our task is to check whether is it possible to split the numbers in two sets such that absolute difference of the sum of numbers in the two sets is equal to M and their gcd(greatest common divisor) is 1. Examples: Input : 5 7 Output : Yes Here,N=5 and M=7 Total sum… Read More »

C++ Programs Mathematical
GCD

Remove Duplicates in an Arithmetic Progression (AP) Series

Given an arithmetic progression and having any number of duplicates, we have to find the index of first occurrence of duplicate element in the series. After getting the index we will remove the duplicates from the series and thus will provide the usual AP series. Note: All duplicates will be adjacent. Examples: Input : arr[] = {2,4,6,6,6,8,10}; Common… Read More »

Arrays Java Programs Mathematical
Arithmetic Progression (AP)

Print array as first element is first maximum and second element is first minimum and so on

Given an array of unique integers, print the array in such a way that the first element is first maximum and second element is first minimum and so on. We have to Rearrange an array in maximum minimum form using Two Pointer Technique. Examples: Input : arr[] = {7, 1, 2, 3, 4, 5, 6} Output : 7… Read More »

Arrays C++ Programs Dynamic Programming
Two-pointer

Efficient LRU Cache Implementation with get() and set() Methods

LRU cache implementation: Here we have two methods get and set which are defined as follows: get(x) : If the key x exists in the cache, returns its value and update reference position in the list. Else returns -1. set(x,y) : Inserts the value if the key x is not already present. If the cache reaches its capacity… Read More »

Analysis C++ Programs Hash Queue

Distributing Natural Numbers into Two Sets with Equal Absolute Sum

Given N and M, distribute first N natural numbers in two sets such that the absolute sum of the numbers in the two sets is equal to M. If possible, print the sum of the numbers in the two sets separated by a space, otherwise, print “Not Possible“. Examples: Input : 7 4 Output : 16 12 Explanation… Read More »

C++ Programs Mathematical
Numbers Sum

Find Sum of a Sequence Defined by Tn = n^2 – (n – 1)^2

A sequence, whose nth term is defined by: Tn = (n)2 – (n – 1)2. The task is to calculate the sum of first n term of the sequence i.e find Sn where, Sn = T1 + T2 + ….. + Tn-1 + Tn Examples: Input : n = 2 Output : 4 T1 = 12 – 02… Read More »

C++ Programs Mathematical

Posts navigation

  • ← Previous
  • 1
  • …
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • …
  • 40
  • Next →

Recent Posts

  • Four Pillars of Object-Oriented Programming (OOPS)
  • Minimize Difference Between Sum of Squares in Array Permutation
  • Find the occurrence of every element among all possible subarrays of the array
  • Compare Two Lists
  • Convert Number n to 1 in Minimum Steps
  • Generate All Distinct Subsequences of Length m from Numbers 1 to n with Repetitions
  • Default Parameters in Python Functions
  • Check if given string contains Even 1’s and Odd 0’s
  • Check if a Clique Can Be Divided into Two Equal Halves
  • Python Methods to Remove Spaces from Dictionary Values

Categories

  • Algorithms
  • Analysis
  • Arrays
  • Backtracking
  • Bit Magic
  • Blog
  • C
  • C Programs
  • C++
  • C++ Programs
  • Combinatorial
  • Compiler Design
  • Computer Networks
  • Computer Organization and Architecture
  • Data Structures
  • DBMS
  • Difference Between
  • Digital Logic
  • Divide and Conquer
  • Dynamic Programming
  • GATE CS
  • Git
  • Graph
  • Greedy
  • Hash
  • Heap
  • HTML
  • Internship
  • Interviews
  • Java
  • Java Programs
  • JavaScript
  • Linked List
  • Machine Learning
  • Mathematical
  • Matrix
  • Misc
  • MongoDB
  • MySQL
  • NoSQL
  • Operating Systems
  • Pattern Searching
  • Python
  • Python Programs
  • Queue
  • Recursion
  • Searching
  • Sorting
  • SQL
  • Stack
  • Strings
  • Tree
  • Web Technology

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
About Us | Contact | Feedback | Privacy Policy | Copyright
Sitemap